コード例 #1
0
ファイル: AlbumManager.cs プロジェクト: yasinfmd/musicApi
        //bak
        public async Task <BaseResponse <string> > Delete(AlbumDto album)
        {
            BaseResponse <string> baseResponse = new BaseResponse <string>();

            var files = album.Images;

            if (files.Count > 0)
            {
                string pathBuild = Path.Combine(Directory.GetCurrentDirectory(), "Uploads\\");
                foreach (var item in files)
                {
                    string[] fileName = item.Path.Split("Uploads/");
                    pathBuild = Path.Combine(pathBuild, fileName[fileName.Length - 1]);
                    var deletedFileFromStorage = _filesService.DeleteFile(pathBuild);
                    var deletedFile            = await _filesService.Delete(new FilesDto { Id = item.Id, Path = item.Path });
                }
                var result = await _albumRepository.DeleteById(album.Id);

                baseResponse.Result = result > 0 ? "Success Delete" : null;
            }
            else
            {
                var result = await _albumRepository.DeleteById(album.Id);

                baseResponse.Result = result > 0 ? "Success Delete" : null;
            }
            return(baseResponse);
        }
コード例 #2
0
        /// <summary>
        /// Remove an Album
        /// </summary>
        /// <remarks>Delete an Album</remarks>
        /// <response code="500">Internal Server Error</response>
        /// <response code="404">Not Found</response>
        /// <response code="400">Bad Request</response>
        /// <response code="200">Ok</response>
        /// <param name="id">Album Id</param>
        /// <returns>Status of operation</returns>
        public override IHttpActionResult Delete(int?id)
        {
            try
            {
                if (!id.HasValue)
                {
                    return(Content(HttpStatusCode.BadRequest, new { message = "Invalid parameter.", status = HttpStatusCode.BadRequest }));
                }

                Album album = _repository.SelectById(id.Value);

                if (album == null)
                {
                    return(Content(HttpStatusCode.NotFound, new { message = "The response didn't return any data.", status = HttpStatusCode.NotFound }));
                }

                _repository.DeleteById(id.Value);

                return(Content(HttpStatusCode.OK, new { message = "The item was successfully removed.", status = HttpStatusCode.OK }));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
コード例 #3
0
 public long Delete(ObjectId id)
 {
     try
     {
         return(_albumRepository.DeleteById(id));
     }
     catch
     {
         throw new HttpResponseException(HttpStatusCode.BadRequest);
     }
 }