Example #1
0
        public async Task<ActionResult> Upload(FormCollection formData)
        {
            var albumID = Convert.ToInt32(formData["Albums"]);

            for (var i = 0; i < Request.Files.Count; i++)
            {
                var fileBase = Request.Files[i];

                if (fileBase != null)
                {
                    var photo = new Photo
                    {
                        AlbumID = albumID,
                        Description = formData["Description"],
                        ContentType = fileBase.ContentType
                    };

                    var photoService = new PhotoStorageService();

                    await photoService.UploadPhotoAsync(photo, fileBase);

                    unitOfWork.PhotoRepository.Insert(photo);
                    unitOfWork.Save();
                }
            }
            return RedirectToAction("Index", new { AlbumID = albumID });
        }
Example #2
0
        public async Task<bool> DeletePhotos(List<int> photoIDList)
        {
            bool returnValue;

            if (photoIDList.Count == 0) return false;

            try
            {
                var photoService = new PhotoStorageService();

                var photos = unitOfWork.PhotoRepository.Get().Where( x => photoIDList.Contains(x.PhotoID)).ToList();

                unitOfWork.PhotoRepository.DeleteByList(photos);

                returnValue = await photoService.DeletePhotos(photos);
                 
                unitOfWork.Save();
            }
            catch (Exception ex)
            {
                throw new HttpRequestException(ex.Message);
            }

            return returnValue;
        }