Пример #1
0
 public ActionResult Edit(PlaceViewModel model)
 {
     if (ModelState.IsValid)
     {
         restaurantService.SaveOrUpdatePlace(model);
         return View("_success");
     }
     else
     {
         ModelState.AddModelError("","Los datos del restaurante no fueron correctos.");
     }
     return View(model);
 }
Пример #2
0
        public void SaveOrUpdatePlace(PlaceViewModel Restaurant)
        {
            var p = new Place();
            if (Restaurant.Id.HasValue)
            {
                p = placesRepository.GetPlace(Restaurant.Id.Value);
                if (p == default(Place))
                    throw new KeyNotFoundException("La id del restaurante no existe.");

                var oldAddress = p.Address;
                p.CloseHour = Restaurant.CloseHours;
                p.OpenHour = Restaurant.OpenHours;
                p.CityId = Int32.Parse(Restaurant.CityId);
                p.CategoryId = Int32.Parse(Restaurant.CategoryId);
                oldAddress.Street = Restaurant.Address;
                oldAddress.ZipCode = Restaurant.ZipCode;
                oldAddress.Col = Restaurant.Colony;
                p.Name = Restaurant.Name;
                p.Phone = Restaurant.Phone;
                if (Restaurant.Image != null ) {
                    if (!ImageService.ValidateImage(Restaurant.Image)) throw new Exception("Imagen en formato invalido.");
                    ImageService.Image = Restaurant.Image;
                    ImageService.DirectoryPath = p.Slug;
                    p.ImgUrl = ImageService.SaveImage();
                    ImageService.Dispose();
                }
                p.Slug = UrlExtensionHelper.CreateSlug(Restaurant.Name);
            }
            else
            {
                p.Address = new Address
                {
                    Col = Restaurant.Colony,
                    Street = Restaurant.Address,
                    ZipCode = Restaurant.ZipCode
                };
                p.CategoryId = Int32.Parse(Restaurant.CategoryId);
                p.CityId = Int32.Parse(Restaurant.CityId);
                p.CloseHour = Restaurant.CloseHours;
                p.OpenHour = Restaurant.OpenHours;
                p.CreatedDate = DateTime.Now;
                p.Phone = Restaurant.Phone;
                p.ImgUrl = Restaurant.ImgUrl;
                p.Name = Restaurant.Name;
                var slug = UrlExtensionHelper.CreateSlug(Restaurant.Name);
                p.Slug = slug;
                if (Restaurant.Image != null)
                {
                    ImageService.Image = Restaurant.Image;
                    ImageService.DirectoryPath = slug;
                    p.ImgUrl = ImageService.SaveImage();
                    ImageService.Dispose();
                }
            }

            placesRepository.SaveOrUpdate(p);
        }
Пример #3
0
        public ActionResult Upload(PlaceViewModel model)
        {
            if (ModelState.IsValid){
                try
                {
                    restaurantService.SaveOrUpdatePlace(model);
                    return View("_success");
                }
                catch(Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                    return View(model);
                }
            }
            else
                ModelState.AddModelError("","Los datos proporcionados no fueron correctos.");

            return View(model);
        }