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));
        }
        // CreateAlbum <username> <albumName> <backgroundColor> <tagName1> ... <tagNameN>
        public string Execute(string[] data)
        {
            string  username = data[0];
            UserDto userDTO  = userService.ByUsername <UserDto>(username);

            if (userDTO == null || userDTO.IsDeleted == true)
            {
                throw new ObjectNotFoundException(typeof(User).Name, username);
            }
            string albumName = data[1];

            if (albumService.Exists(albumName))
            {
                throw new DuplicateObjectException(typeof(Album).Name, albumName);
            }
            string colorName = data[2];

            if (!Enum.TryParse(colorName, true, out Color backgroundColor))
            {
                throw new ObjectNotFoundException(typeof(Color).Name, colorName);
            }
            string[] tagNames = data.Skip(3).Select(t => t.ValidateOrTransform()).ToArray();
            if (tagNames.Any(tagName => !tagService.Exists(tagName)))
            {
                throw new InvalidObjectException("tags");
            }
            albumService.Create(userDTO.Id, albumName, backgroundColor.ToString(), tagNames);
            return(String.Format(SuccessMessage, albumName));
        }
Beispiel #3
0
        public IActionResult Insert(AlbumViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Create", model));
            }

            var path = $"wwwroot\\uploads\\{model.Photo.FileName}";

            using (var stream = new FileStream(path, FileMode.Create))
            {
                model.Photo.CopyTo(stream);
            }

            var album = new Album
            {
                Name        = model.Name,
                Description = model.Description,
                PhotoLink   = $"/uploads/{model.Photo.FileName}"
            };

            _albumService.Create(album);

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Create(CreateAlbumFormModel album)
        {
            var userId = User.Id();

            var artistList = await _artists.ArtistsList(userId);

            if (ModelState.IsValid)
            {
                var albumID = _service.Create(
                    album.Name,
                    album.ImageUrl,
                    album.Year,
                    album.Format,
                    album.MediaCondition,
                    album.SleeveCondition,
                    album.Notes,
                    album.ArtistId);

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["ArtistId"] = new SelectList(artistList, "Id", "Name", album.ArtistId);

            return(View(album));
        }
        public string Execute(string[] data)
        {
            string username   = data[0];
            string albumTitle = data[1];
            string bgColor    = data[2];

            string[] tags = data.Skip(3).ToArray();

            if (!userSessionService.IsLoggedIn())
            {
                throw new ArgumentException("You are not logged in!");
            }

            bool isUserExist = userService.Exists(username);

            if (!isUserExist)
            {
                throw new ArgumentException($"User {username} not found!");
            }

            int userId = userService.ByUsername <User>(username).Id;

            bool isAlbumExist = albumService.Exists(albumTitle);

            if (isAlbumExist)
            {
                throw new ArgumentException($"Album {albumTitle} exists!");
            }

            var isBackgroundColorExist = Enum.TryParse(bgColor, out Color backgroundColor);

            if (!isBackgroundColorExist)
            {
                throw new ArgumentException($"Color {bgColor} not found!");
            }

            for (int i = 0; i < tags.Length; i++)
            {
                tags[i] = tags[i].ValidateOrTransform();
                TagDto tag = new TagDto {
                    Name = tags[i]
                };

                bool isTagExist = tagService.Exists(tags[i]);

                if (!isTagExist)
                {
                    throw new ArgumentException("Invalid tags!");
                }
            }

            albumService.Create(userId, albumTitle, backgroundColor, tags);

            return($"Album {albumTitle} successfully created!");
        }
Beispiel #6
0
        public ActionResult Create()
        {
            PostFormModel postFormModel = new PostFormModel();

            if (albumService.AllAlbumsByUser(User.Identity.GetUserId()).Count == 0)
            {
                albumService.Create("Default Album", User.Identity.GetUserId(), "Your Default Album");
            }
            postFormModel.Albums = this.albumService.AlbumsByUserForDD(User.Identity.GetUserId());
            return(View(postFormModel));
        }
        public IHttpActionResult Post(AlbumViewModel albumViewModel)
        {
            var requestorid = GetRequestorId();

            var albumDto = AlbumViewModelAdapter.BuildAlbumDto(albumViewModel);

            _albumService.Create(albumDto, requestorid);

            var response = Request.CreateResponse(HttpStatusCode.Created, albumViewModel);

            return(ResponseMessage(response));
        }
Beispiel #8
0
        public JsonResult CreateAlbum(string albumName, string userEmail)
        {
            var user = userService.GetByEmail(userEmail);

            albumService.Create(new AlbumEntity()
            {
                Name         = albumName,
                UserId       = user.Id,
                CreationDate = DateTime.Now
            });

            return(Json(true));
        }
Beispiel #9
0
        public void Search()
        {
            string[] filenames = Directory.GetFiles("D:/WEB_Onion/OAA.Web/wwwroot/tracks/", "*.mp3", SearchOption.AllDirectories);
            foreach (var link in filenames)
            {
                // nameTrack-nameArtist.mp3
                var nameTrack  = "";
                var nameArtist = "";
                var splited    = link.Split("-");
                nameTrack  = splited[0].Split("/")[5];
                nameArtist = splited[1].Replace(".mp3", "");

                var linkT = "http://localhost:52527/tracks/" + nameTrack + "-" + nameArtist + ".mp3";

                var nameT = nameTrack.Replace(" ", "+");
                var nameA = nameArtist.Replace(" ", "+");

                if (artistService.GetAll().Where(a => a.Name == nameArtist).Count() == 0)
                {
                    AddArtistToDb(nameArtist);
                }

                var   nameAlbum = trackService.GetAlbumTrackName(nameA, nameT);
                Album album     = albumService.GetAll().Where(a => a.NameArtist == nameArtist).FirstOrDefault(b => b.Name == nameAlbum);

                if (album == null)
                {
                    Album alb = albumService.GetAlbum(nameArtist, nameAlbum);
                    alb.ArtistId = artistService.Get(nameArtist).Id;
                    albumService.Create(alb);
                }

                if (trackService.GetAll().Where(a => a.Name == nameTrack).FirstOrDefault(b => b.NameAlbum == nameAlbum) != null)
                {
                    AddLinkToDb(nameTrack, nameArtist, linkT);
                }
                else
                {
                    Track track = trackService.AddTrackFromLast(nameTrack, nameArtist, linkT);
                    track.AlbumId   = albumService.GetAll().Where(a => a.Name == nameAlbum).FirstOrDefault(b => b.NameArtist == nameArtist).Id;
                    track.NameAlbum = nameAlbum;
                    trackService.Create(track);
                }
            }
        }
Beispiel #10
0
        public PartialViewResult GetTopAlbum(string name, int page, int count)
        {
            List <Album>          topAlbums = new List <Album>();
            List <AlbumViewModel> listModel = new List <AlbumViewModel>();
            var listAlbInDb = _albumService.GetAlbumsByNameArtist(name);

            if (listAlbInDb.Count() != 0)
            {
                foreach (Album a in listAlbInDb)
                {
                    var modelAlb = new AlbumViewModel()
                    {
                        NameAlbum  = a.Name,
                        NameArtist = a.NameArtist,
                        Cover      = a.Cover
                    };
                    listModel.Add(modelAlb);
                }
            }

            var nameForRequest = name.Replace(" ", "+");

            topAlbums = _albumService.GetTopAlbum(nameForRequest, page, count);
            foreach (var alb in topAlbums)
            {
                var albumInDb = _albumService.Get(alb.Name);
                if (albumInDb == null)
                {
                    alb.ArtistId = _artistService.Get(name).Id;
                    _albumService.Create(alb);
                    var model = new AlbumViewModel()
                    {
                        NameAlbum  = alb.Name,
                        Cover      = alb.Cover,
                        NameArtist = alb.NameArtist
                    };
                    listModel.Add(model);
                }
            }
            return(PartialView(listModel));
        }
Beispiel #11
0
        // CreateAlbum <username> <albumTitle> <BgColor> <tag1> <tag2>...<tagN>
        public string Execute(string[] data)
        {
            var username        = data[0];
            var albumTitle      = data[1];
            var backGroundColor = data[2];
            var tags            = data.Skip(3).ToArray();

            if (username != this.userSessionService.User.Username)
            {
                throw new InvalidOperationException("Invalid credentials!");
            }

            if (!userService.Exists(username))
            {
                throw new ArgumentException($"User {username} not found!");
            }

            if (albumService.Exists(username))
            {
                throw new ArgumentException($"Album {albumTitle} exists!");
            }

            var color = Enum.TryParse <Color>(backGroundColor, true, out Color parsedColor);

            if (!color)
            {
                throw new ArgumentException($"Color {backGroundColor} not found!");
            }

            if (!tags.All(x => tagService.Exists(x)))
            {
                throw new ArgumentException("Invalid tags!");
            }

            var user  = userService.ByUsername <UserDto>(username);
            var album = albumService.Create(user.Id, albumTitle, parsedColor, tags);

            return($"Album {albumTitle} successfully created!");
        }
        // CreateAlbum <username> <albumTitle> <BgColor> <tag1> <tag2>...<tagN>
        public string Execute(string[] data)
        {
            string username  = data[0];
            string albumName = data[1];
            string bgColor   = data[2];

            string[] tags = data.Skip(3).Select(p => Utilities.TagUtilities.ValidateOrTransform(p)).ToArray();

            if (username != Session.CurrentUser.Username)
            {
                return(OperationNotAllowed);
            }

            if (albumService.Exists(albumName))
            {
                return(String.Format(AlbumExists, albumName));
            }

            if (!userService.Exists(username))
            {
                return(String.Format(UserNotFound, username));
            }

            var user = userService.ByUsername <User>(username);

            try
            {
                albumService.Create(user.Id, albumName, bgColor, tags);
            }
            catch (Exception e)
            {
                return(e.Message);
            }

            return(String.Format(SuccessMessage, albumName));
        }