public async Task <IActionResult> AddAlbum(AlbumCreateDto model)
        {
            if (ModelState.IsValid)
            {
                var result = await _albumService.Create(model);

                if (result.IsSuccess)
                {
                    return(RedirectToAction("Album", new { artistId = model.ArtistId }));
                }

                throw new Exception("No se pudo registrar el álbum");
            }

            // Volvemos a pasar el modelo en caso falle para que cargue la data de nuevo
            var artist = await _artistService.Get(model.ArtistId);

            var resultViewModel = new AlbumViewModel
            {
                ArtistId    = artist.ArtistId,
                ArtistName  = artist.Name,
                AlbumCreate = model
            };

            // Especificamos la ruta de la vista manualmente
            return(View("Album", resultViewModel));
        }
示例#2
0
        public ActionResult Create(AlbumCreateDto albumCreateDto)
        {
            if (albumCreateDto == null)
            {
                return(Problem());
            }

            var userIdFromRepo = _unitOfWork.Sellers.GetById(albumCreateDto.SellerId).UserId;

            //Check if the user has permission
            var user   = HttpContext.User;
            int userId = int.Parse(user.Claims.FirstOrDefault(c => c.Type == "Id").Value);

            if (userId != userIdFromRepo)
            {
                return(Forbid());
            }

            var repoAlbum = _mapper.Map <Album>(albumCreateDto);

            _unitOfWork.Albums.Add(repoAlbum);
            _unitOfWork.SaveChanges();

            return(NoContent());
        }
示例#3
0
        public Wall ToGroupWall(AlbumCreateDto groupWallDto, int groupId)
        {
            WallType wallType  = dbContext.WallTypes.Where(wt => wt.Title == groupWallDto.Type.ToString()).First();
            Wall     groupWall = new Wall()
            {
                WallTypeId = wallType.Id,
                Title      = groupWallDto.Title,
                GroupId    = groupId
            };

            return(groupWall);
        }
示例#4
0
        public Wall WallFromCreation(AlbumCreateDto newAlbumCreate, int ownerId)
        {
            WallType wallType = dbContext.WallTypes.Where(wt => wt.Title == newAlbumCreate.Type.ToString()).First();
            Wall     wall     = new Wall()
            {
                OwnerId    = ownerId,
                Title      = newAlbumCreate.Title,
                WallTypeId = wallType.Id
            };

            return(wall);
        }
        public ActionResult <AlbumReadDto> CreateAlbum(AlbumCreateDto albumCreateDto)
        {
            var albumModel = _mapper.Map <Album>(albumCreateDto);

            _repository.CreateAlbum(albumModel);

            _repository.SaveChanges();

            var albumReadDto = _mapper.Map <AlbumReadDto>(albumModel);

            return(CreatedAtRoute(nameof(GetAlbum), new { Id = albumReadDto.Id }, albumCreateDto));
        }
示例#6
0
        public ActionResult CreateWall(AlbumCreateDto newAlbumCreate, int ownerId, bool groupWall)
        {
            if (ModelState.IsValid)
            {
                if (groupWall)
                {
                    pageService.CreateGroupWall(newAlbumCreate, ownerId);
                    return(RedirectToAction("GetGroupAlbums", new { groupId = ownerId, type = newAlbumCreate.Type }));
                }
                else
                {
                    pageService.CreateWall(newAlbumCreate, ownerId);
                }
                return(RedirectToAction("AlbumList", new{ userId = ownerId, type = newAlbumCreate.Type }));
            }

            return(View());
        }
示例#7
0
        public async Task <ResponseHelper> Create(AlbumCreateDto model)
        {
            var result = new ResponseHelper();

            try
            {
                var entry = Mapper.Map <Album>(model);

                await _context.AddAsync(entry);

                await _context.SaveChangesAsync();

                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }

            return(result);
        }
示例#8
0
        public void CreateGroupWall(AlbumCreateDto newGroupAlbum, int groupId)
        {
            Wall wall = wallMapper.ToGroupWall(newGroupAlbum, groupId);

            pageManager.AddWall(wall);
        }
示例#9
0
        public void CreateWall(AlbumCreateDto newAlbumCreate, int ownerId)
        {
            Wall wall = wallMapper.WallFromCreation(newAlbumCreate, ownerId);

            pageManager.AddWall(wall);
        }