Ejemplo n.º 1
0
        public ActionResult EditOutfit(int id)
        {
            var departments = new SelectList(departmentRepository.GetDepartments().Select(d => d.DepartmentName));

            var        Outfit = OutfitRepository.Get(id);
            OutfitEdit model  = new OutfitEdit
            {
                Id                = Outfit.Id,
                Title             = Outfit.Title,
                Price             = Outfit.Price,
                Discount          = Outfit.Discount,
                DepartmentName    = Outfit.DepartmentName,
                Description       = Outfit.Description,
                ExistingPhotoPath = Outfit.PhotoPath
            };

            foreach (var d in departments)
            {
                if (d.Value == model.DepartmentName)
                {
                    d.Selected = true;
                    break;
                }
            }

            ViewBag.Department = departments;

            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult EditOutfit(OutfitEdit model)
        {
            if (ModelState.IsValid)
            {
                Outfit Outfit = new Outfit
                {
                    Id             = model.Id,
                    Title          = model.Title,
                    Price          = model.Price,
                    Discount       = model.Discount,
                    Description    = model.Description,
                    DepartmentName = model.DepartmentName,
                    PhotoPath      = model.ExistingPhotoPath
                };

                if (model.Photo != null)
                {
                    if (model.ExistingPhotoPath != null)
                    {
                        string FilePath = Path.Combine(HostingEnvironment.WebRootPath, "images", model.ExistingPhotoPath);
                        System.IO.File.Delete(FilePath);
                    }
                    Outfit.PhotoPath = ProcessUploadedFile(model);
                }

                OutfitRepository.Edit(Outfit);
                TempData["message"] = $"{Outfit.Title} has been edited";
            }
            else
            {
                ViewBag.Departments = new SelectList(departmentRepository.GetDepartments().Select(d => d.DepartmentName));
                return(View(model));
            }
            return(RedirectToAction("Outfits"));
        }
Ejemplo n.º 3
0
 public bool UpdateOutfit(int outfitid, OutfitEdit model)
 {
     using (var ctx = new ApplicationDbContext())
     {
         var entity =
             ctx
             .Outfits
             .Single(e => e.OutfitID == outfitid);
         entity.OutfitName = model.OutfitName;
         entity.Top        = model.Top;
         entity.Bottom     = model.Bottom;
         return(ctx.SaveChanges() == 1);
     }
 }
Ejemplo n.º 4
0
        public IHttpActionResult Put(int outfitid, OutfitEdit model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateOutfitService();

            if (!service.UpdateOutfit(outfitid, model))
            {
                return(InternalServerError());
            }

            return(Ok());
        }