public async Task <IActionResult> Post([FromBody] AlbumDto item) { try { return(Ok(await _repo.CreateAsync(item))); } catch (Exception ex) { return(StatusCode(500, ex)); } }
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)); }
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) }); }
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); } }
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)); } }
public async Task CreateAsync(Album album) { await _albumRepository.CreateAsync(album); }