public async Task <IActionResult> Create([Bind("Id,Name,Email,Gender,RegisteredDate,SelectedEvents,AdditionalRequest,Events")] UserViewModel users) { for (int i = 0; i < users.Events.Count(); i++) { if (users.Events[i].IsSelected) { if (users.SelectedEvents != null) { users.SelectedEvents += "," + users.Events[i].EventName; } else { users.SelectedEvents += users.Events[i].EventName; } ModelState.Remove("SelectedEvents"); } } if (ModelState.IsValid) { Users usr = new Users() { Email = users.Email, Name = users.Name, Gender = users.Gender, RegisteredDate = users.RegisteredDate, SelectedEvents = users.SelectedEvents, AdditionalRequest = users.AdditionalRequest, Id = Guid.NewGuid() }; _context.Add(usr); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } users.Events = new List <EventViewModel> { new EventViewModel { EventName = "Day 1", IsSelected = false }, new EventViewModel { EventName = "Day 2", IsSelected = false }, new EventViewModel { EventName = "Day 3", IsSelected = false } }; return(View(users)); }
static void Main(string[] args) { using (AssignmentDBContext db = new AssignmentDBContext()) { Items i = new Items() { ItemName = "honor", ItemPrice = 9999 }; db.Add(i); db.SaveChanges(); } }