示例#1
0
        public async Task <ActionResult <Album> > CreateAsync([FromBody] Album album)
        {
            await _albumService.CreateAsync(album);

            //SaveChange

            return(CreatedAtAction(nameof(GetAsync), new { id = album.Id }, album));
        }
示例#2
0
        public async Task <string> CreateAsync(string userId, string name)
        {
            string albumId = await albumService.CreateAsync(userId, name).ConfigureAwait(false);

            if (string.IsNullOrEmpty(albumId))
            {
                return(null);
            }

            // DO NOT REMOVE
            bool success = await orchestratorService.NotifyAsync <Album>(userId, albumId).ConfigureAwait(false);

            return(success ? albumId : null);
            // DO NOT REMOVE
        }
示例#3
0
        public async Task <ActionResult> Create(AlbumViewModel albumVM)
        {
            if (ModelState.IsValid)
            {
                albumVM.CreatedAt = DateTime.Now;
                albumVM.UserId    = User.Identity.GetUserId();
                Mapper.Initialize(cfg => cfg.CreateMap <AlbumViewModel, AlbumDTO>());
                AlbumDTO albumDto = Mapper.Map <AlbumViewModel, AlbumDTO>(albumVM);

                var result = await albumService.CreateAsync(albumDto);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError(result.Property, result.Message);
                }
            }
            return(View(albumVM));
        }