public IActionResult EditStudent(int id) { var model = new EditStudentModel(); model.LoadData(id); return(View(model)); }
public IActionResult EditStudent( [Bind(nameof(EditStudentModel.Id), nameof(EditStudentModel.Name), nameof(EditStudentModel.Username), nameof(EditStudentModel.Email))] EditStudentModel model) { if (ModelState.IsValid) { try { model.EditStudent(); model.Response = new ResponseModel("Student Added Successfully", ResponseType.Success); return(RedirectToAction("Index")); } catch (DuplicationException ex) { model.Response = new ResponseModel(ex.Message, ResponseType.Failure); } catch (Exception ex) { model.Response = new ResponseModel("Failed to Add Student", ResponseType.Failure); } } return(View(model)); }
public EditStudentModel GetEditModelForStudent(string userid) { EditStudentModel Model = new EditStudentModel(); List <SubjectEditModel> SubModel = new List <SubjectEditModel>(); Model.User = Users.GetById(userid); if (Model.User.Type == "Student") { foreach (AllSubjectModel model in AllSubjectModels.GetAll()) { List <SubjectModel> item = SubjectModels.GetAll().Where(x => x.UserId == Model.User.Id).ToList(); bool active = item.FirstOrDefault(x => x.SubjectId == model.Id) != null ? true : false; SubModel.Add(new SubjectEditModel { Subject = model, Active = active }); } } Model.Subjects = SubModel; return(Model); }
public void UpdateStudent(EditStudentModel Model) { db.SubjectModels.RemoveRange(db.SubjectModels.Where(x => x.UserId == Model.User.Id).ToList()); ApplicationUser User = GetById(Model.User.Id); User.Name = Model.User.Name; User.Surname = Model.User.Surname; foreach (SubjectEditModel model in Model.Subjects) { SubjectModel sub = model.Active ? new SubjectModel { SubjectId = model.Subject.Id, Type = Model.User.Type, UserId = Model.User.Id } : null; if (sub != null) { db.SubjectModels.Add(sub); } } db.SaveChanges(); }
public ActionResult UpdateStudent(EditStudentModel Model) { Users.UpdateStudent(Model); return(RedirectToAction("Index", "Home")); }