public virtual async Task <IActionResult> Admin() { var viewModel = new ContactAdminViewModel(); viewModel.Contacts = await _context.GetAllAsync <Contact>(); viewModel.ContactReasons = await _context.GetAllAsync <ContactReason>(); return(View(viewModel)); }
public async Task <IActionResult> Edit(int id) { var contact = await this.contacts.ByIdAsync(id); if (contact == null) { return(NotFound()); } var model = new ContactAdminViewModel { Id = contact.Id, Title = contact.Title, Message = contact.Message, ContactType = contact.ContactType, IsAnswered = contact.IsAnswered }; return(View(model)); }
public async Task <IActionResult> Edit(ContactAdminViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var contact = await this.contacts.ByIdAsync(model.Id); if (contact == null) { return(NotFound()); } await this.contacts.EditAsync(model.Id, model.Title, model.Message, model.ContactType, model.IsAnswered); TempData.AddSuccessMessage($"Successfully edited contact {contact.Title}."); return(this.RedirectToCustomAction( nameof(HomeController.Index), nameof(HomeController), new { area = string.Empty })); }
public ActionResult MarkClassControl(ContactAdminViewModel contactViewModel) { var listSudent = _dbContext.ClassStudent.Where(a => a.Class.Id == contactViewModel.ClassNameId && a.YearId == contactViewModel.YearId).ToList(); List <Contact> list_Contact = new List <Contact>(); for (int i = 0; i < listSudent.Count; i++) { var temp = new Contact() { }; temp.CLassId = contactViewModel.ClassNameId; temp.SubjectId = contactViewModel.SubjectId; temp.SemesterId = contactViewModel.SemesterId; temp.YearId = contactViewModel.YearId; temp.StudentId = listSudent[i].StudentId; var check = _dbContext.Contacts.Any(a => a.CLassId == contactViewModel.ClassNameId && a.SubjectId == contactViewModel.SubjectId && a.SemesterId == contactViewModel.SemesterId && a.YearId == contactViewModel.YearId && a.StudentId == temp.StudentId); if (!check) { _dbContext.Contacts.Add(temp); _dbContext.SaveChanges(); } } //var list = _dbContext.Contacts.Include("Student").Include("Class").Include("Semester").Include("Year").Where(a => a.CLassId == contactViewModel.ClassId && a.SubjectId == contactViewModel.SubjectId && a.SemesterId == contactViewModel.SemesterId && a.YearId == contactViewModel.YearId).ToList(); //TempData["list"] = list; //return RedirectToAction("Edit"); var list2 = _dbContext.Contacts.Include("Subject").Include("Student").Include("Class").Include("Semester").Include("Year").Where(a => a.CLassId == contactViewModel.ClassNameId && a.SubjectId == contactViewModel.SubjectId && a.SemesterId == contactViewModel.SemesterId && a.YearId == contactViewModel.YearId).ToList(); if (list2.Count.Equals(0)) { return(RedirectToAction("MarkControl")); } TempData["list"] = list2; return(RedirectToAction("Edit")); }