示例#1
0
 public void Create(AlbumDto albumDto, Guid requestorId)
 {
     if ((_userRepository.GetUserById(requestorId)).Roles[0].Name.Equals("Subscriber") || (_userRepository.GetUserById(requestorId)).Roles[0].Name.Equals("Admin"))
     {
         _albumRepository.AddAlbum(AlbumAdapter.BuildAlbum(albumDto), albumDto.UsersWithAccess);
     }
 }
示例#2
0
        public ActionResult AddOrEdit(AlbumDto album)
        {
            try
            {
                if (album.ImageUpload != null)
                {
                    GenerateImagePath(album);
                }

                if (album.AlbumID == 0)
                {
                    albumRepository.AddAlbum(mapper.Map <Album>(album));
                }
                else
                {
                    albumRepository.EditAlbum(mapper.Map <Album>(album));
                }

                return(Json(new { success = true, html = RazorToString.RenderRazorView(this, "GetAll", mapper.Map <IEnumerable <AlbumDto> >(albumRepository.GetAllAlbums())), message = "Submitted Successfully" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
示例#3
0
        public HttpResponseMessage PostAlbums(Album album)
        {
            int ambumId = _repo.AddAlbum(album);
            HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, album);

            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { id = ambumId }));
            return(response);
        }
示例#4
0
 public ActionResult Create(EditAlbumViewModel model)
 {
     if (ModelState.IsValid)
     {
         Album album = AlbumMapper.MapEditAlbumViewModel(model, userID);
         albumRepository.AddAlbum(album);
     }
     return(Content(model.Name));
 }
示例#5
0
        public ViewResult NewAlbum()
        {
            Album newAlb = new Album {
                Name = Request.Form["Name"]
            };

            repository.AddAlbum(newAlb);
            repository.SaveContext();
            return(View());
        }
        public ActionResult Create([Bind(Include = "Title, Description, Place, City, Country, From, To, Photos")]
                                   NewAlbumViewModel newAlbumViewModel)
        {
            if (ModelState.IsValid)
            {
                var aAlbum = newAlbumViewModel.ToAlbumEntity();
                _albumRepository.AddAlbum(aAlbum);
                return(RedirectToAction("Index"));
            }

            newAlbumViewModel.Photos = null;

            return(View(newAlbumViewModel));
        }
示例#7
0
        public async Task <ActionResult <AlbumGetResponse> > CreateAlbum([FromBody] AlbumPostRequest albumPostRequest)
        {
            if (albumPostRequest.ArtistId == Guid.Empty || albumPostRequest.GenreId == Guid.Empty)
            {
                throw new ArgumentNullException(nameof(albumPostRequest));
            }

            var albumToAdd = _mapper.Map <Album>(albumPostRequest);

            albumToAdd.Id = Guid.NewGuid();

            _albumRepository.AddAlbum(albumToAdd);
            await _albumRepository.SaveAsync();

            if (albumPostRequest.Tracks.Any())
            {
                foreach (var track in albumPostRequest.Tracks)
                {
                    var trackToAdd = _mapper.Map <Track>(track);
                    trackToAdd.Id      = Guid.NewGuid();
                    trackToAdd.AlbumId = albumToAdd.Id;
                    _albumRepository.AddTrackToAlbum(trackToAdd);
                }
                await _albumRepository.SaveAsync();
            }
            var albumResponse = _mapper.Map <AlbumGetResponse>(albumToAdd);

            return(CreatedAtRoute(
                       "GetAlbum",
                       new
            {
                version = HttpContext.GetRequestedApiVersion().ToString(),
                albumId = albumToAdd.Id
            },
                       albumResponse));
        }
示例#8
0
        public async Task <AlbumDTO> AddAlbum(AlbumDTO album)
        {
            try
            {
                Album newAlbum = _mapper.Map <Album>(album);
                newAlbum.AlbumId = Guid.NewGuid();
                newAlbum.Songs   = new List <Song>();
                newAlbum.Artist  = new Artist();

                foreach (var songId in album.SongIds)
                {
                    Song song = await GetSongBySongId(songId);

                    if (song != null)
                    {
                        await _albumRepository.AddAlbumSong(new AlbumSong()
                        {
                            AlbumSongId = Guid.NewGuid(),
                            SongId      = songId,
                            AlbumId     = newAlbum.AlbumId,
                        });
                    }
                }

                Artist artist = await GetArtistByArtistId(album.ArtistId);

                if (artist != null)
                {
                    newAlbum.ArtistId = artist.ArtistId;
                }

                await _albumRepository.AddAlbum(newAlbum);

                return(album);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }