Esempio n. 1
0
 /// <summary>
 /// Attempts to delete file
 /// </summary>
 /// <param name="fileName"></param>
 public static void RemoveItem(string fileName)
 {
     try
     {
         lock (padlock)
         {
             AzureBlob.DeleteBlob(fileName);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
        public IHttpActionResult DeleteProfilePic()
        {
            var file = HttpContext.Current.Request.Files.Count > 0 ? HttpContext.Current.Request.Files[0] : null;

            if (file != null && file.ContentLength > 0)
            {
                string fl = file.FileName;
                if (file.FileName == UserAuthentication.Identity().imgprofile)
                {
                    return(Ok());
                }
            }

            else
            {
                AzureBlob      BlobManagerObj = new AzureBlob(1);
                photogEntities db             = new photogEntities();
                var            id             = UserAuthentication.Identity().id;
                var            user           = db.Users.FirstOrDefault(x => x.id == id);

                if (user.imgprofile == null)
                {
                    return(Ok());
                }

                else if (!string.IsNullOrWhiteSpace(BlobManagerObj.DeleteBlob(user.id.ToString(), User.Identity.GetProfilePhotoLink())))
                {
                    user.imgprofile = null;
                    db.SaveChanges();

                    UserAuthentication.UpdateClaim();

                    return(Ok());
                }
            }
            return(BadRequest());
        }
Esempio n. 3
0
        public async Task <ActionResult> Edit(CreatePackageViewModel data)
        {
            if (ViewBag.StudioID != data.studioid)
            {
                return(RedirectToAction("packagehome"));
            }

            if (!db.UserStudios.ToList().Any(x => x.userid == UserAuthentication.Identity().id&& x.studioid == data.studioid))
            {
                return(RedirectToAction("Error500", "Home", new { errormsg = "You picked the wrong studio Fool!" }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (data.price < data.depoprice || data.price <= 0 || data.depoprice < 0)
                    {
                        TempData["error"] = "Invalid price setting";
                        data.images       = db.Packages.Find(data.id).PackageImages.ToList();
                        return(View("editpackage", data));
                    }

                    var edit = db.Packages.First(x => x.id == data.id);
                    edit.depositprice = data.depoprice;
                    edit.details      = string.IsNullOrWhiteSpace(data.details) ? null : data.details;
                    edit.name         = data.name;
                    edit.price        = data.price;
                    edit.studioid     = data.studioid;

                    var img = db.PackageImages.Where(x => x.PackageID == data.id);

                    if (!string.IsNullOrWhiteSpace(data.ImgName))
                    {
                        if (img == null || img.FirstOrDefault(x => x.ImageName.ToLower() == data.ImgName.ToLower()) == null)
                        {
                            AzureBlob BlobManagerObj = new AzureBlob(2);
                            foreach (var item in img)
                            {
                                BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName));
                            }

                            db.PackageImages.RemoveRange(img);
                            PackageImage package = new PackageImage {
                                ImageName = data.ImgName
                            };
                            edit.PackageImages.Add(package);
                        }
                    }

                    else
                    {
                        AzureBlob BlobManagerObj = new AzureBlob(2);
                        foreach (var item in img)
                        {
                            BlobManagerObj.DeleteBlob(data.studioid.ToString(), String.Format("https://storagephotog2.blob.core.windows.net/studio-data/{0}/{1}", item.Package.studioid, item.ImageName));
                        }
                        db.PackageImages.RemoveRange(img);
                    }


                    db.SaveChanges();

                    await UpdateFirebaseOrder(edit);

                    return(RedirectToAction("PackageHome"));
                }
                catch (Exception e)
                {
                    return(RedirectToAction("Error500", "Home", new { errormsg = e.Message }));
                }
            }

            return(View("editpackage", data));
        }