public void Insert(PropertyPictureDTO picture, out Guid?id) { id = Connector.ExecuteScalar <Guid?>(insertQuery, new Dictionary <string, object>() { { "Property", picture.Property }, { "Description", picture.Description } }); }
public CreateResult Create(PropertyPictureDTO picture) { Repository.Insert(picture, out Guid? id); if (id != null) { picture.Id = id.Value; } return(CreateResult.OK); }
public ActionResult EditPropertyPicture(Guid propertyId, Guid pictureId) { PartnerBLL partnerBLL = new PartnerBLL(WebApp.Connector); PropertyDTO property = AddEditPropertyPicture_Base(partnerBLL, propertyId); if (property != null) { PropertyPictureDTO picture = partnerBLL.ReadPropertyPictureById(Account, propertyId, pictureId); return(picture != null?View(picture) as ActionResult : HttpNotFound()); } else { return(HttpNotFound()); } }
public ActionResult AddPropertyPicture(Guid id, AddPropertyPictureDTO request) { bool hasAValidPicture = false; try { using (new Bitmap(request.Picture.InputStream)) { hasAValidPicture = true; } } catch { } PartnerBLL partnerBLL = new PartnerBLL(WebApp.Connector); PropertyDTO property = AddEditPropertyPicture_Base(partnerBLL, id); if (ModelState.IsValid) { if (hasAValidPicture) { PropertyPictureDTO picture = new PropertyPictureDTO() { Property = property, Description = request.Description }; PartnerBLL.AddPropertyPictureResult result = partnerBLL.AddPropertyPicture(Account, id, picture); switch (result) { case PartnerBLL.AddPropertyPictureResult.OK: string imgRepository = HostingEnvironment.MapPath("~/img"); request.Picture.SaveAs($"{imgRepository}/{picture.Id}.bin"); TempData["Result"] = "PropertyPictureHasBeenAdded"; return(RedirectToAction("ViewProperty")); case PartnerBLL.AddPropertyPictureResult.NotFound: return(HttpNotFound()); default: return(BadRequest()); } } else { AddError("Picture", "FileIsNotAValidPicture"); return(View(request)); } } else { return(property != null?BadRequestWithErrors() as ActionResult : HttpNotFound()); } }
public ActionResult DeletePropertyPicture(Guid propertyId, Guid pictureId) { PartnerBLL partnerBLL = new PartnerBLL(WebApp.Connector); if (Request.HttpMethod == "GET") { PropertyPictureDTO picture = partnerBLL.ReadPropertyPictureById(Account, propertyId, pictureId); if (picture != null) { ViewBag.PropertyId = propertyId; return(View(picture)); } else { return(HttpNotFound()); } } else { PartnerBLL.DeletePropertyPictureResult result = partnerBLL.DeletePropertyPicture(Account, propertyId, pictureId); switch (result) { case PartnerBLL.DeletePropertyPictureResult.OK: TempData["Result"] = "PropertyPictureHasBeenDeleted"; try { string image = HostingEnvironment.MapPath($"~/img/{pictureId}.img"); System.IO.File.Delete(image); } catch { } return(RedirectToAction("ViewProperty", new { id = propertyId })); case PartnerBLL.DeletePropertyPictureResult.NotFound: return(HttpNotFound()); default: return(BadRequest()); } } }
public ActionResult EditPropertyPicture(Guid propertyId, Guid pictureId, PropertyPictureDTO picture) { PartnerBLL partnerBLL = new PartnerBLL(WebApp.Connector); PropertyDTO property = AddEditPropertyPicture_Base(partnerBLL, propertyId); if (ModelState.IsValid) { PartnerBLL.UpdatePropertyPictureResult result = partnerBLL.UpdatePropertyPicture(Account, propertyId, pictureId, picture); switch (result) { case PartnerBLL.UpdatePropertyPictureResult.OK: TempData["Result"] = "PropertyPictureHasBeenEdited"; return(RedirectToAction("ViewProperty", new { id = propertyId })); case PartnerBLL.UpdatePropertyPictureResult.NotFound: return(HttpNotFound()); default: return(BadRequest()); } } else { return(property != null?BadRequestWithErrors() as ActionResult : HttpNotFound()); } }
public AddPropertyPictureResult AddPropertyPicture(PartnerDTO partner, Guid propertyId, PropertyPictureDTO picture) { Connector.IsTransaction = true; try { PropertyBLL propertyBLL = new PropertyBLL(Connector); PropertyDTO property = propertyBLL.ReadById(propertyId); if (property.Partner.Id == partner.Id) { PropertyPictureBLL pictureBLL = new PropertyPictureBLL(Connector); picture.Property = property; PropertyPictureBLL.CreateResult result = pictureBLL.Create(picture); if (result == PropertyPictureBLL.CreateResult.OK) { Connector.CommitTransaction(); } else { Connector.RollbackTransaction(); } return((AddPropertyPictureResult)(byte)result); } else { return(AddPropertyPictureResult.NotFound); } } catch (Exception exception) { Connector.RollbackTransaction(); throw exception; } }