Exemplo n.º 1
0
 public async Task <IActionResult> Post([FromBody] AlbumDto item)
 {
     try
     {
         return(Ok(await _repo.CreateAsync(item)));
     }
     catch (Exception ex)
     {
         return(StatusCode(500, ex));
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Post([FromBody] AlbumDTO album)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var id = await _repository.CreateAsync(album);

            album.Id = id;

            return(CreatedAtAction("Get", new { id }, album));
        }
Exemplo n.º 3
0
        public async Task <Result <string> > AddAlbum(AddAlbumInput input)
        {
            Album album = new Album()
            {
                Images   = input.Images,
                Location = input.Location,
                Password = input.Password,
                Title    = input.Title,
                Date     = input.Date
            };

            return(new Result <string>()
            {
                Success = true,
                Data = await _albumRepository.CreateAsync(album)
            });
        }
Exemplo n.º 4
0
        private async Task SaveAsync()
        {
            var album = new Album
            {
                Id       = Id,
                Title    = Title,
                ArtistId = ArtistId,
                Year     = Year,
                Cover    = CoverBytes
            };

            if (Id == 0)
            {
                await _albumRepository.CreateAsync(album);
            }
            else
            {
                await _albumRepository.UpdateAsync(album);
            }
        }
Exemplo n.º 5
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));
            }
        }
Exemplo n.º 6
0
 public async Task CreateAsync(Album album)
 {
     await _albumRepository.CreateAsync(album);
 }