public ActionResult Create(FormCollection form) { MeetingViewModel meetingModel = new MeetingViewModel(); if (ModelState.IsValid) { meetingModel.Time = DateTime.Parse(form["Time"]); meetingModel.Description = form["Description"]; meetingModel.Place = form["Place"]; string category = form["CategoryID"]; GetActiveCategory(meetingModel, category); string[] checkedValues = form.GetValues("assignChkBx"); List<int> contactIds = GetActiveContacts(checkedValues); Meeting meeting = meetingModel.ToMeeting(); meetingRepository.InsertOrUpdate(meeting, contactIds, User.Identity.Name); meetingRepository.Save(); return RedirectToAction("Index"); } return View(meetingModel); }
public ActionResult Edit(int id) { Meeting meeting = meetingRepository.Get(id); MeetingViewModel meetingModel = new MeetingViewModel(meeting); List<Category> categoriesDal = categoryRepository.All(User.Identity.Name).ToList(); List<CategoryViewModel> categories = new List<CategoryViewModel>(); foreach (var item in categoriesDal) { categories.Add(new CategoryViewModel(item)); } List<Contact> contactsDal = contactRepository.All(User.Identity.Name).ToList(); List<ContactViewModel> contacts = new List<ContactViewModel>(); foreach (var item in contactsDal) { contacts.Add(new ContactViewModel(item)); } ViewBag.Contacts = contacts; ViewBag.CategoryID = new SelectList(categories, "Name", "Name", meeting.Category != null ? meeting.Category.Name : string.Empty); return View(meetingModel); }
private void GetActiveCategory(MeetingViewModel meetingModel, string category) { IQueryable<Category> cat = categoryRepository.All(User.Identity.Name); foreach (var item in cat) { if (item.Name == category) { meetingModel.Category = new CategoryViewModel(item); break; } } }
public ActionResult Delete(int id) { Meeting meeting = meetingRepository.Get(id); MeetingViewModel meetingModel = new MeetingViewModel(meeting); return View(meetingModel); }