コード例 #1
0
        public ICommandResult Handle(CreateAlbumCommand command)
        {
            var categoryQuery = _categoryRepository.GetById(command.CategoryId);
            var genderQuery   = _genderRepository.GetById(command.GenderId);

            Gender   gender   = new Gender(genderQuery.Id, genderQuery.Title, genderQuery.Description);
            Category category = new Category(categoryQuery.Id, categoryQuery.Title, categoryQuery.Description);
            Album    album    = new Album(command.Title, gender, category, command.Image);

            AddNotifications(album.Notifications);

            if (Invalid)
            {
                return(new CommandResult(false, MessagesUtil.FormFail, Notifications));
            }

            bool result = _repository.Create(album);

            if (!result)
            {
                return(new CommandResult(false, MessagesUtil.CreateError, Notifications));
            }

            return(new CommandResult(true, MessagesUtil.CreatedSuccess));
        }
コード例 #2
0
        public void Post(AlbumDTO value)
        {
            Album model = new Album()
            {
                Name        = value.Name,
                ReleaseYear = value.ReleaseYear,
                StudioId    = value.StudioId
            };

            IAlbumRepository.Create(model);
            for (int i = 0; i < value.ArtistId.Count; i++)
            {
                ArtistAlbum ArtistAlbum = new ArtistAlbum()
                {
                    AlbumId  = model.Id,
                    ArtistId = value.ArtistId[i]
                };
                IArtistAlbumRepository.Create(ArtistAlbum);
            }
            for (int i = 0; i < value.SongId.Count; i++)
            {
                SongAlbum SongAlbum = new SongAlbum()
                {
                    AlbumId = model.Id,
                    SongId  = value.ArtistId[i]
                };
                ISongAlbumRepository.Create(SongAlbum);
            }
        }
コード例 #3
0
        public ActionResult EditAlbum(Album album, HttpPostedFileBase Image = null, int AuthorId = 0, int CategoryId = 0)
        {
            if (ModelState.IsValid)
            {
                if (Image != null)
                {
                    string fileName = Path.GetFileName(Image.FileName);
                    string filePath = "~/Content/Images" + fileName;
                    album.ImagePath = filePath;
                    Image.SaveAs(Server.MapPath(filePath));
                }
                if (CategoryId != 0)
                {
                    album.CategoryId = CategoryId;
                }
                if (AuthorId != 0)
                {
                    album.AuthorId = AuthorId;
                }

                albumRepository.Create(album);

                string message = "Action Succeded";
                return(RedirectToAction("Albums", new { message = message }));
            }
            else
            {
                ViewBag.Authors    = authorRepository.GetList();
                ViewBag.Categories = categoryRepository.GetList();
                return(View(album));
            }
        }
コード例 #4
0
        public async Task <ActionResult <Album> > Post([FromBody] Album album)
        {
            album.Id = await _repo.GetNextId();

            await _repo.Create(album);

            return(new OkObjectResult(album));
        }
コード例 #5
0
        public async Task <IActionResult> CreateAlbum([FromRoute] Guid artistId, [FromBody] AlbumForCreationDto albumToCreate)
        {
            var albumEntity = Mapper.Map <Album>(albumToCreate);

            albumEntity.Id       = Guid.NewGuid();
            albumEntity.ArtistId = artistId;

            _albumRepository.Create(albumEntity);

            if (!await _albumRepository.SaveChangesAsync())
            {
                throw new Exception($"adding album to artist {artistId} failed");
            }


            return(CreatedAtRoute("GetAlbum", new { artistId, id = albumEntity.Id }, albumEntity));
        }
コード例 #6
0
 public void Create(AlbumEntity album)
 {
     albumRepository.Create(new DalAlbum()
     {
         Name         = album.Name,
         UserId       = album.UserId,
         CreationDate = album.CreationDate
     });
     uow.Commit();
 }
コード例 #7
0
 public ActionResult <Model.Album> Create([FromBody] Model.RawAlbum value)
 {
     try
     {
         var created = repository.Create(value);
         return(CreatedAtAction(nameof(GetDetails), new { name = created.Name, owner = created.Owner }, created));
     } catch (ArgumentException e)
     {
         return(BadRequest(new { error = e.Message }));
     }
 }
コード例 #8
0
 public void SaveAlbum(Album album)
 {
     try
     {
         _albumRepository.Create(album);
         _unitOfWork.SaveChanges();
     }
     catch (Exception ex)
     {
         LogError(ex);
     }
 }
コード例 #9
0
        public IActionResult Create(AlbumViewModel albumViewModel)
        {
            if (!ModelState.IsValid)
            {
                albumViewModel.Bands = _bandRepository.GetAll();

                return(View(albumViewModel));
            }

            _albumRepository.Create(albumViewModel.Album);

            return(RedirectToAction("List"));
        }
コード例 #10
0
        public async Task <IActionResult> Create([Bind("AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album, [FromServices] IAlbumRepository albumRepository, CancellationToken cancellationToken = default)
        {
            if (ModelState.IsValid)
            {
                album = await albumRepository.Create(album, cancellationToken);

                cancellationToken.ThrowIfCancellationRequested();

                return(RedirectToAction("Index"));
            }
            await BuildCreateView(cancellationToken);

            return(View(album));
        }
コード例 #11
0
 public int CreateAlbum(businessModels.FullAlbum model)
 {
     model.AuthorId         = User.Identity.GetUserId();
     model.CreationDate     = DateTime.Now;
     model.ModificationDate = DateTime.Now;
     if (ModelState.IsValid)
     {
         //creating photos
         var album = Mapper.Map <Album>(model);
         albumRepository.Create(album);
         return(album.Id);
     }
     throw new HttpResponseException(HttpStatusCode.InternalServerError);
 }
コード例 #12
0
 public ActionResult Create(Album a)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var album = _albumRepository.Create(a);
             return(RedirectToAction("Details", new { id = album.Id }));
         }
         catch (Exception ex)
         {
             return(View(a));
         }
     }
     return(RedirectToAction("Index"));
 }
コード例 #13
0
        public Album Create(string albumName, string artistName, int genreId, Int16 price, System.Web.HttpPostedFileBase cover)
        {
            Album album = new Album
            {
                Name             = albumName,
                Artist           = ArtistRepository.CreateOrGet(artistName),
                GenreId          = genreId,
                CreationDateTime = DateTime.Now,
                Price            = price
            };

            AlbumRepository.Create(album);

            UploadResizeAndSave(ref album, cover);

            return(album);
        }
コード例 #14
0
        public Album UpdateAlbum(Album album)
        {
            return(ExecuteFaultHandledOperation(() =>
            {
                IAlbumRepository albumRepository = _genericRepositoryFactory.GetGenericRepository <IAlbumRepository>();

                Album updatedEntity = null;

                if (album.AlbumId == 0)
                {
                    updatedEntity = albumRepository.Create(album).Result;
                }
                else
                {
                    updatedEntity = albumRepository.Update(album).Result;
                }

                return updatedEntity;
            }));
        }
コード例 #15
0
 public void CreateAlbum(AlbumEntity album)
 {
     albumRepository.Create(album.ToDal());
     uow.Commit();
 }
コード例 #16
0
ファイル: AlbumService.cs プロジェクト: ArtemGontar/MusicApi
 public void Create(Album album)
 {
     _albumRepository.Create(album);
 }
コード例 #17
0
 public void Create(IElementSettings settings, IUnitOfWork unitOfWork = null)
 {
     _albumRepository.Create((AlbumSettings)settings, unitOfWork);
 }
コード例 #18
0
 public void Criar(Album entity)
 {
     _albumRepository.Create(entity);
 }
コード例 #19
0
 public ActionResult Create(Album album)
 {
     albumRepo.Create(album);
     return(RedirectToAction("Index"));
 }
コード例 #20
0
 public bool Insert(Album album)
 {
     _repository.Create(album);
     return(_repository.SaveChanges());
 }