Beispiel #1
0
 public IHttpActionResult Put([FromBody] EstateModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             return(BadRequest(ModelState));
         }
         _estateService.Update(model);
         return(Ok(model));
     }
     catch (Exception ec)
     {
         return(BadRequest(ec.Message));
     }
 }
Beispiel #2
0
        public ActionResult Edit(EstateModel model, HttpPostedFileBase ImageFile)
        {
            if (!ModelState.IsValid)
            {
                return(null);
            }

            if (ImageFile != null)
            {
                if (model.Image != null)
                {
                    var currentImagePath = Server.MapPath("~" + Constants.UploadPath + model.Image);

                    if (System.IO.File.Exists(currentImagePath))
                    {
                        System.IO.File.Delete(currentImagePath);
                    }
                }

                var imageName = Guid.NewGuid() + ".jpg";
                ImageFile.SaveAs(Server.MapPath("~" + Constants.UploadPath + imageName));
                model.Image = imageName;
            }

            var estateDto = Mapper.Map <EstateDto>(model);
            int id;

            if (model.EstateId == 0)
            {
                var result = _estateService.Add(estateDto);
                id = result.EstateId;
            }
            else
            {
                var result = _estateService.Update(estateDto);
                id = result.EstateId;
            }

            return(RedirectToAction("Edit", new { id }));
        }