Esempio n. 1
0
        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 })));
        }
 public ActionResult Create(Establishment establishment)
 {
     try
     {
         if (ModelState.IsValid)
         {
             repository.Save(establishment);
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(establishment));
         }
     }
     catch
     {
         return(View());
     }
 }
Esempio n. 3
0
 public ActionResult Delete(Guid id)
 {
     EstablishmentRepository.Delete(id);
     EstablishmentRepository.Save();
     return(Redirect(Url.Action("GetAll", "Establishment")));
 }