public ActionResult AddOrUpdate(ClassroomModel model) { if (!ModelState.IsValid) { return(View(model)); } var isCreated = model.Id == Guid.Empty; var classroom = new Classrooms(); if (!isCreated) { classroom = ClassroomRepository.GetById(model.Id); } classroom.Title = model.Title; classroom.Establishment_Id = model.Establishment_Id; classroom.Establishments = EstablishmentRepository.GetById(model.Establishment_Id); classroom.User_Id = model.UserId; classroom.Users = UserRepository.GetById(model.UserId); classroom.Year_Id = model.YearId; classroom.Years = YearRepository.GetById(model.YearId); if (isCreated) { ClassroomRepository.Add(classroom); } ClassroomRepository.Save(); return(Redirect(Url.Action("Get", "Classroom", new { id = classroom.Id }))); }
public ActionResult AddOrUpdate(EstablishmentModel model) { if (!ModelState.IsValid) { return(View(model)); } var isCreated = model.Id == Guid.Empty; var establishment = new Establishments(); if (!isCreated) { establishment = EstablishmentRepository.GetById(model.Id); } establishment.Name = model.Name; establishment.Academie_Id = model.AcademyId; establishment.Academies = AcademyRepository.GetByName(model.Academy); establishment.Address = model.Address; establishment.PostCode = model.PostCode; establishment.Town = model.Town; establishment.User_Id = model.UserId; establishment.Users = UserRepository.GetById(model.UserId); if (isCreated) { EstablishmentRepository.Add(establishment); } EstablishmentRepository.Save(); return(Redirect(Url.Action("Get", "Establishment", new { id = establishment.Id }))); }
// GET: Establishment/Edit/5 public ActionResult Edit(int id) { var establishment = repository.GetById(id); if (establishment == null) { return(HttpNotFound()); } return(View(establishment)); }
public ActionResult AddOrUpdate(Guid?id, Guid?academyId) { var model = new EstablishmentModel(); model.UserId = GlobalVariables.UserId; if (id.HasValue) { model = EstablishmentModel.ToModel(EstablishmentRepository.GetById(id.Value)); } if (academyId.HasValue) { model.AcademyId = academyId.Value; } return(View(model)); }
public ActionResult Get(Guid id) { var model = EstablishmentModel.ToModel(EstablishmentRepository.GetById(id)); return(View(model)); }