Exemplo n.º 1
0
        public ActionResult Create(Furniture furniture)
        {
            if (ModelState.IsValid)
            {
                var fileName  = Path.GetFileNameWithoutExtension(furniture.ImageFile.FileName);
                var extension = Path.GetExtension(furniture.ImageFile.FileName);
                fileName = fileName + Guid.NewGuid().ToString() + extension;
                furniture.FurnitureImage = "~/PhotoUploads/Furnitures/" + fileName;
                fileName = Path.Combine(Server.MapPath("~/PhotoUploads/Furnitures/"), fileName);
                furniture.ImageFile.SaveAs(fileName);
                //resizing image
                MemoryStream ms       = new MemoryStream();
                WebImage     webImage = new WebImage(fileName);
                if (webImage.Width > 700)
                {
                    webImage.Resize(700, 564, false);
                    webImage.Save(fileName);
                }
                _furnitureRepository.Insert(furniture);
                _unitOfWork.Complete();
                return(RedirectToAction("Index"));
            }

            return(View(furniture));
        }
Exemplo n.º 2
0
 public IHttpActionResult Post([FromBody] Furniture furniture)
 {
     try
     {
         _furnitureRepository.Insert(furniture);
         _unitOfWork.Complete();
         return(Created(Request.RequestUri + "/" + furniture.ID, furniture));
     }
     catch (Exception)
     {
         return(InternalServerError());
     }
 }