예제 #1
0
        public bool DeleteImage(string blobName)
        {
            if (blobName == null)
            {
                return(false);
            }

            try
            {
                ImageUpload imgUpload = new ImageUpload();
                imgUpload.DeleteImageByNameWithMiniatures(blobName);
                try
                {
                    _zdjecieRepo.DeleteImage(blobName);
                    _zdjecieRepo.SaveChanges();
                }
                catch
                {
                    return(false);
                }
            }
            catch
            {
            }

            return(false);
        }
예제 #2
0
        public ActionResult UploadImage(HttpPostedFileBase fileBase)
        {
            if (fileBase != null && fileBase.ContentLength > 0)
            {
                try
                {
                    ImageUpload imageUpload       = new ImageUpload();
                    string      nameWithExtension = imageUpload.UploadImageAndReturnImageName(fileBase);

                    if (nameWithExtension == null)
                    {
                        return(RedirectToAction("Lista", "Galeria"));
                    }


                    try
                    {
                        Zdjecie img = new Zdjecie()
                        {
                            UzytkownikId = User.Identity.GetUserId(),
                            Name         = nameWithExtension
                        };
                        _zdjecieRepo.AddImage(img);
                        _zdjecieRepo.SaveChanges();
                    }
                    catch
                    {
                        imageUpload.DeleteImageByNameWithMiniatures(nameWithExtension);
                    }
                }
                catch
                {
                }
            }

            return(RedirectToAction("Lista", "Galeria"));
        }