Q:

How to get logged in UserName and add his name to database?

In my application i have Form for logged users and after complete questionnaire by user i want to add answers with UserName to database.
Im writing method to save values and have some troubles with saving UserName to my database table column. How should look correct syntax to save that UserName?
Model method
public string Answer1 { get; set; }
public string Answer2 { get; set; }

 public void Save()
    {

        var db2 = new DBEntities();
        db2.Questionnaire.Add(new Questionnaire() {
            Answer1 = Answer1,
            Answer2 = Answer2,
            //ETC...

        });
        db2.SaveChanges();
    }

Controller
    public ActionResult Form()
    {
        var model = new FormViewModel();
        return View(model);
    }

    [HttpPost]
    public ActionResult Form(FormViewModel model)
    {
        if (ModelState.IsValid)
        {
            var now = DateTime.Now;
            model.CreationDate = now;

            var usr = User.Identity.GetUserName();//getting logged UserName
            db2.Questionnaire.Add(model.usr);//this is incorrect attempt to save

            model.Save(); //saving method
            return RedirectToAction("Index");
        }
        return View(model);
    }

My database tabel looks like
CREATE TABLE [dbo].[Questionnaire](
[Id] [int] IDENTITY(1,1) NOT NULL,
[CreationDate] [datetime] NOT NULL,
[UserName] [nvarchar](50) NOT NULL,
[Answer1] [nvarchar](50) NULL,
[Answer2] [nvarchar](512) NULL,
//ETC..
PRIMARY KEY CLUSTERED

A:

you have to set the username, answer etc to the model:
model:
public string UserName { get; set; }
public string Answer1 { get; set; }
public string Answer2 { get; set; }

 public void Save()
 {
    var db2 = new DBEntities();
    db2.Questionnaire.Add(new Questionnaire() {
      Answer1 = Answer1,
      Answer2 = Answer2,
      UserName = UserName,
      //ETC...
        });
        db2.SaveChanges();
    }

Controller
var usr = User.Identity.GetUserName();//getting logged UserName
model.Username = usr;
model.Save(); //saving method

