Beispiel #1
0
        public async Task <Result> DeleteAlbum(string id)
        {
            Album album = await _albumRepository.FindAsync(id);

            List <string>       imageVariantsIds = new List <string>();
            List <UploadedFile> uploadedFiles    = new List <UploadedFile>();

            if (album.Images != null)
            {
                album.Images.ForEach(image =>
                {
                    imageVariantsIds.AddRange(GetImageVariantsIds(image));
                });

                uploadedFiles = await _uploadedFilesRepository.
                                DeleteUploadedFiles(imageVariantsIds);

                await _blobStore.DeleteBlobs(GetBlobsIds(uploadedFiles));
            }

            await _albumRepository.DeleteAsync(id);

            return(new Result()
            {
                Success = true
            });
        }
Beispiel #2
0
 public async Task <IActionResult> Delete(Guid id)
 {
     try
     {
         return(Ok(await _repo.DeleteAsync(id)));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
Beispiel #3
0
 public async Task <IActionResult> Delete(Guid id)
 {
     try
     {
         return(Ok(await _repo.DeleteAsync(id)));
     }
     catch (Exception ex) //отлавливаем ошибку, если она попадается в тру
     {
         return(StatusCode(500, ex));
     }
 }
Beispiel #4
0
        public async Task <IActionResult> Delete(int id)
        {
            var ok = await _repository.DeleteAsync(id);

            if (ok)
            {
                return(NoContent());
            }

            return(NotFound());
        }
Beispiel #5
0
        public async Task <ActionResult> DeleteAlbum(Guid albumId)
        {
            var album = await _albumRepository.QueryByIdAsync(albumId);

            if (album != null)
            {
                await FileHelper.DeleteFileAsync(Path.Combine(FileHelper.BaseFilePath, album.UserId.ToString(), albumId.ToString()));//删除相应文件

                var result = await _albumRepository.DeleteAsync(album);

                if (result > 0)
                {
                    return(Ok());
                }
            }
            return(NotFound());
        }
        public async Task DeleteAsync(AlbumEntity albumEntity)
        {
            await _repository.DeleteAsync(albumEntity);

            var message = new
            {
                ImageUri = albumEntity.ImageUri,
                Id       = $"{albumEntity.Id}",
            };

            var    jsonMessage       = JsonConvert.SerializeObject(message);
            var    bytesJsonMessage  = UTF8Encoding.UTF8.GetBytes(jsonMessage);
            string jsonMessageBase64 = Convert.ToBase64String(bytesJsonMessage);

            await _queue.DeleteAsync(jsonMessageBase64);

            var partitionName = "delete";

            await _historicoRepository.InsertAsync(new AlbumHistoricoEntity(albumEntity, partitionName));
        }
Beispiel #7
0
 public async Task <bool> DeleteAsync(int id)
 {
     return(await _albumRepository.DeleteAsync(id));
 }
Beispiel #8
0
 public async Task <bool> DeleteAlbumAsync(int id, CancellationToken ct = default(CancellationToken))
 {
     return(await _albumRepository.DeleteAsync(id, ct));
 }
Beispiel #9
0
        public async Task <ActionResult> Album(MusicViewModel album, HttpPostedFileBase file)
        {
            var model = new MusicViewModel
            {
                Albums     = await _albumRepository.GetPageByAlbumTypeAsync(1, 100, album.AlbumTypeId),
                AlbumTypes = await _albumTypeRepository.GetAllyAsync()
            };
            var albumCheck        = new Album();
            var allowedExtensions = new[] {
                ".Jpg", ".png", ".jpg", "jpeg"
            };

            try
            {
                if (!ModelState.IsValid)
                {
                    ModelState.AddModelError(string.Empty, "لطفا مقدار های مناسب پر کنید");
                }
                if (string.IsNullOrEmpty(album.AlbumOldName))
                {
                    album.AlbumOldName = album.AlbumNewName;
                }

                albumCheck = await _albumRepository.GetByAlbumTypeAsync(album.AlbumTypeId, album.AlbumOldName);

                if (album.ActionType == "create" || album.ActionType == "edit")
                {
                    if (albumCheck == null)
                    {
                        if (file != null)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var ext      = Path.GetExtension(file.FileName);
                            if (allowedExtensions.Contains(ext))
                            {
                                string name   = Path.GetFileNameWithoutExtension(fileName);
                                string myfile = name + "_" + album.AlbumNewName + ext;
                                var    path   = Path.Combine(Server.MapPath("~/DownloadCenter/Album"), myfile);
                                album.AlbumImage = "~/DownloadCenter/Album/" + myfile;
                                file.SaveAs(path);
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, "Please choose only Image file");
                            }
                        }

                        var albummodel = new Album
                        {
                            Name        = album.AlbumOldName,
                            Description = album.AlbumDescption,
                            ImageUrl    = album.AlbumImage,
                            AlbumTypeId = album.AlbumTypeId
                        };


                        await _albumRepository.CreateAsync(albummodel);

                        model.Albums = await _albumRepository.GetPageByAlbumTypeAsync(1, 100, album.AlbumTypeId);

                        model.AlbumTypeId = album.AlbumTypeId;

                        //return RedirectToAction("Section", new { surveyName = surveys.SurveyTitle });
                        return(View(model));
                    }
                    else
                    {
                        if (file != null)
                        {
                            var fileName = Path.GetFileName(file.FileName);
                            var ext      = Path.GetExtension(file.FileName);
                            if (allowedExtensions.Contains(ext))
                            {
                                string name   = Path.GetFileNameWithoutExtension(fileName);
                                string myfile = name + "_" + album.AlbumNewName + ext;
                                var    path   = Path.Combine(Server.MapPath("~/DownloadCenter/Album"), myfile);
                                album.AlbumImage = "~/DownloadCenter/Album/" + myfile;
                                file.SaveAs(path);
                            }
                            else
                            {
                                ModelState.AddModelError(string.Empty, "Please choose only Image file");
                            }
                        }

                        albumCheck.Name        = (album.AlbumOldName == album.AlbumNewName ? album.AlbumOldName : album.AlbumNewName);
                        albumCheck.Description = album.AlbumDescption;
                        albumCheck.ImageUrl    = album.AlbumImage ?? albumCheck.ImageUrl;
                        albumCheck.AlbumTypeId = album.AlbumTypeId;

                        await _albumRepository.EditAsync(albumCheck.Id, albumCheck);
                    }
                }
                else
                {
                    await _albumRepository.DeleteAsync(albumCheck.Id);
                }

                model.Albums = await _albumRepository.GetPageByAlbumTypeAsync(1, 100, album.AlbumTypeId);

                model.AlbumTypeId = album.AlbumTypeId;

                //return RedirectToAction("Section", new { surveyName = model.GenreOldName });
                return(View(model));
            }
            catch (Exception e)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(View(model: model));
            }
        }
Beispiel #10
0
 public async Task DeleteAsync(int id)
 {
     await _albumRepository.DeleteAsync(id);
 }