Пример #1
0
        public ActionResult Save(NewLocationVm vm)
        {
            try
            {
                if (vm.Id == null)
                {
                    Location location = new Location()
                    {
                        Id        = Guid.NewGuid(),
                        Name      = vm.Name,
                        CreatedAt = DateTime.Now,
                        CreatedBy = LoggedInUser?.UserName
                    };
                    Db.Locations.Add(location);
                }
                else
                {
                    var location = Db.Locations.FirstOrDefault(x => x.Id == vm.Id);
                    location.Name = vm.Name;
                }
                Db.SaveChanges();

                return(Json(new JsonResponse()
                {
                    IsSucess = true
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new JsonResponse()
                {
                    IsSucess = false, ErrorMessage = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #2
0
 public ActionResult Edit(Guid?id)
 {
     try
     {
         var location = Db.Locations.FirstOrDefault(x => x.Id == id);
         var model    = new NewLocationVm()
         {
             Id   = location.Id,
             Name = location.Name,
         };
         return(PartialView("~/Views/Locations/Add.cshtml", model));
     }
     catch (Exception ex)
     {
         return(Json(new JsonResponse()
         {
             IsSucess = false, ErrorMessage = ex.Message
         }, JsonRequestBehavior.AllowGet));
     }
 }