コード例 #1
0
 public void Insert(PropertyPictureDTO picture, out Guid?id)
 {
     id = Connector.ExecuteScalar <Guid?>(insertQuery, new Dictionary <string, object>()
     {
         { "Property", picture.Property },
         { "Description", picture.Description }
     });
 }
コード例 #2
0
 public CreateResult Create(PropertyPictureDTO picture)
 {
     Repository.Insert(picture, out Guid? id);
     if (id != null)
     {
         picture.Id = id.Value;
     }
     return(CreateResult.OK);
 }
コード例 #3
0
        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());
            }
        }
コード例 #4
0
        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());
            }
        }
コード例 #5
0
        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());
                }
            }
        }
コード例 #6
0
        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());
            }
        }
コード例 #7
0
 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;
     }
 }