Example #1
0
        public void AlbumShouldBeAdded()
        {
            // setup
            var userModel = new UserModel
            {
                Email        = "*****@*****.**",
                UserPassword = "******",
                FirstName    = "First",
                LastName     = "Last",
                Albums       = new Collection <AlbumModel>()
            };

            var albumModel = new AlbumModel
            {
                Name           = "name",
                DateOfCreation = DateTime.Now,
                Description    = "description"
            };

            // body
            userService.CreateUser("*****@*****.**", "First", "Last");
            albumService.CreateAlbum(userModel.Id, albumModel);

            // tear down
            userModel.Albums.Count.Should().Be(1);
        }
Example #2
0
        public JsonResult SaveAlbum(AlbumModel album)
        {
            var sessionId = this.Session["SessionID"].ToString();
            IUserSessionRepository userSessionRepository = RepositoryClassFactory.GetInstance().GetUserSessionRepository();
            UserSession            userSession           = userSessionRepository.FindByID(sessionId);

            if (userSession == null)
            {
                return(Json(new { errorCode = (int)ErrorCode.Redirect, message = Resources.AdminResource.msg_sessionInvalid }, JsonRequestBehavior.AllowGet));
            }

            InsertResponse response = new InsertResponse();

            album.Title = album.Title.Length > 200 ? album.Title.Substring(0, 100) + "..." : album.Title;
            if (!string.IsNullOrEmpty(album.Description))
            {
                album.Description = album.Description.Length > 300 ? album.Description.Substring(0, 296) + "..." : album.Description;
            }
            else
            {
                album.Description = null;
            }
            album.ActionURL   = string.Format("{0}-{1}", UrlSlugger.ToUrlSlug(album.Title), UrlSlugger.Get8Digits());
            album.CreatedDate = DateTime.Now;
            album.AlbumID     = Guid.NewGuid().ToString();
            album.CreatedBy   = userSession != null ? userSession.UserID : string.Empty;

            response = _albumService.CreateAlbum(album);

            return(Json(new { errorCode = response.ErrorCode, message = response.Message }, JsonRequestBehavior.AllowGet));
        }
Example #3
0
        public async Task <IActionResult> CreateAlbum([FromBody] AlbumDto albumDto)
        {
            var requestor = await GetUser();

            var album = await _albumService.CreateAlbum(requestor, albumDto.Name);

            return(Ok(album));
        }
        public AlbumViewModel Adicionar(AlbumViewModel albumviewmodel)
        {
            var album = Mapper.Map <AlbumViewModel, Album>(albumviewmodel);

            _AlbumService.CreateAlbum(album);

            return(albumviewmodel);
        }
Example #5
0
 public ActionResult Create(Album album)
 {
     if (ModelState.IsValid)
     {
         _albumService.CreateAlbum(album);
         return(RedirectToAction("Index"));
     }
     return(View());
 }
        public void Init()
        {
            _interpret1Id = 1;
            _interpret1   = new InterpretDTO
            {
                ID       = _interpret1Id,
                Name     = "System of a down",
                Language = Language.English,
                IsPublic = false
            };

            _interpret2Id = 2;
            _interpret2   = new InterpretDTO
            {
                ID       = _interpret2Id,
                Name     = "Linkin Park",
                Language = Language.English,
                IsPublic = false
            };
            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);


            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = _interpret1Id,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = _interpret2Id,
                Name        = "Meteora",
                Year        = 2003
            };

            _albumService.CreateAlbum(_album1, _interpret1Id);
            _albumService.CreateAlbum(_album2, _interpret2Id);
        }
Example #7
0
        public async Task <Profile> CreateProfileAsync(string accountId, string userName, string profileDescription)
        {
            var profile = new Profile(accountId, userName, profileDescription);

            profile = await _profileRepository.AddAsync(profile);

            await _albumService.CreateAlbum(profile.Id);

            return(profile);
        }
        public ActionResult Create(AlbumModel model)
        {
            if (ModelState.IsValid)
            {
                _albumService.CreateAlbum(model.Album.Name, model.Album.Description, model.Album.IsPublic, model.Album.Tags, model.SelectedCategoryId.Value);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Example #9
0
        public IActionResult OnPostCreateAlbum(string albumName, int dayOffset)
        {
            if (!IsLoggedIn)
            {
                return(Page());
            }

            _albumService.CreateAlbum(albumName, null, dayOffset);
            LoadAlbums();
            return(RedirectToPage(PageName));
        }
Example #10
0
        public async Task <IActionResult> CreateAlbum(Guid bandId, [FromBody] AlbumToCreate model)
        {
            if (!await _service.BandExists(bandId))
            {
                return(NotFound());
            }

            var album = await _service.CreateAlbum(bandId, model.Title, model.ReleaseDate, model.Art);

            return(CreatedAtAction(nameof(GetAlbumForBandById), new { bandId, album.Id }, _mapper.Map <Album>(album)));
        }
Example #11
0
        public async Task <IActionResult> Create(AlbumCreateInputModel inputModel)
        {
            if (ModelState.IsValid)
            {
                var profileId = _userManager.GetProfileId(User);
                await _albumService.CreateAlbum(profileId, inputModel.Title, inputModel.Description, inputModel.Picture);

                return(RedirectToAction("Albums", "Profile"));
            }
            return(View(inputModel));
        }
        public ActionResult Create([Bind(Include = "AlbumId,GenreId,ArtistId,Title,Price,AlbumArtUrl")] Album album)
        {
            if (ModelState.IsValid)
            {
                albumService.CreateAlbum(album);
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistId = new SelectList(albumService.FindAlbums(), "ArtistId", "Name");
            ViewBag.GenreId  = new SelectList(genreService.FindGenres(), "GenreId", "Name");
            return(View(album));
        }
Example #13
0
 public ResultModel CreateAlbum([FromBody] string title)
 {
     try
     {
         int id = _albumService.CreateAlbum(title, null);
         return(new ResultModel(true, id));
     }
     catch (Exception e)
     {
         _logService.LogError(e);
         return(new ResultModel(e));
     }
 }
        public IActionResult Create(AlbumCreateInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/Albums/Create"));
            }

            Album album = model.MapTo <Album>();

            albumService.CreateAlbum(album);

            return(Redirect("/Albums/All"));
        }
Example #15
0
        // CreateAlbum <username> <albumTitle> <BgColor> <tag1> <tag2>...<tagN>
        public string Execute(string command, params string[] data)
        {
            if (data.Length < 4)
            {
                throw new InvalidOperationException($"Command {command} not valid!");
            }

            string        username   = data[0];
            string        albumTitle = data[1];
            string        BgColor    = data[2];
            List <string> tagNames   = data.Skip(3).ToList();

            return(albumService.CreateAlbum(username, albumTitle, BgColor, tagNames));
        }
        public ActionResult Create(CreateAlbumViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.GenreLookupList  = _genreService.GetAllGenres().Genres.OrderBy(g => g.Name);
                model.ArtistLookupList = _artistService.GetAllArtists().Artists.OrderBy(a => a.Name);

                return(View(model));
            }

            _albumService.CreateAlbum(model.ConvertToCreateAlbumRequest());

            return(RedirectToAction("Index"));
        }
Example #17
0
        private int GetAlbumId()
        {
            int userId = AuthenticationHelper.GetInstance().GetUserId(HttpContext.Current);
            var album  = _albumService.GetUserAlbums(userId).FirstOrDefault();

            if (album != null)
            {
                return(album.AlbumId);
            }
            string username  = _securityService.GetUser(userId).Username;
            string albumName = string.Format("Альбом пользователя {0} ({1})", username, userId);
            int    id        = _albumService.CreateAlbum(albumName, userId);

            return(id);
        }
Example #18
0
        // CreateAlbum <username> <albumTitle> <BgColor> <tag1> <tag2>...<tagN>
        public string Execute(params string[] data)
        {
            var username   = data[0];
            var albumTitle = data[1];
            var bgColor    = data[2];
            var tags       = data.Skip(3).ToArray();

            if (Session.User is null || !Session.User.Username.Equals(username))
            {
                throw new ArgumentException("Invalid credentials!");
            }

            albumService.CreateAlbum(username, albumTitle, bgColor, tags);

            return($"Album {albumTitle} successfully created!");
        }
Example #19
0
        public ActionResult <Message> CreateAlbum(Album album)
        {
            if (album.Picture == null)
            {
                album.Picture = "~/album/timg.png";
            }
            string tmp = HttpContext.Session.GetString("userId");

            if (tmp == "" || tmp == null)
            {
                return(Redirect("/SignIn"));
            }
            var userId = Convert.ToInt32(tmp);

            album.UserID = userId;
            Message message = AlbumService.CreateAlbum(album);

            return(new JsonResult(message));
        }
        public ActionResult Index(AlbumDto albumToCreate)
        {
            //try
            //{
            //    _albumService.CreateAlbum(new AlbumDto() { Price = 101 });
            //}
            //catch (ValidationException ex)
            //{
            //    this.ModelState.AddModelErrors(ex);
            //    return View();
            //}

            if (ModelState.IsValid)
            {
                _albumService.CreateAlbum(albumToCreate);
                return(RedirectToAction("Index"));
            }

            return(View(albumToCreate));
        }
Example #21
0
 public HttpResponseMessage Create([FromBody] string albumName)
 {
     if (albumName == null)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unknown error"));
     }
     try
     {
         _albumService.CreateAlbum(User.Id, albumName);
         return(Request.CreateResponse(HttpStatusCode.Created));
     }
     catch (AlbumAlreadyExistException ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
     }
 }
Example #22
0
        public string Execute(string command, string[] data)
        {
            if (data.Length < 3)
            {
                throw new InvalidOperationException($"Command {command} not valid!");
            }

            if (!userSessionService.IsLoggedIn() || userSessionService.User.Username != data[0])
            {
                throw new InvalidOperationException("Invalid credentials!");
            }

            var username   = data[0];
            var albumTitle = data[1];
            var color      = data[2];
            var tags       = data.Skip(3).Select(t => t.ValidateOrTransform()).ToArray();

            var album = albumService.CreateAlbum(username, albumTitle, color, tags);

            return($"Album {album.Name} successfully created!");
        }
Example #23
0
        public IActionResult Upload(UploadPicture model)
        {
            var fileContents = model.Photo.ToByteArray();
            var albumId      = 0;

            if (model.AlbumTitle != null && model.AlbumId == 0)
            {
                albumId = albums.CreateAlbum(model.AlbumTitle, User.Identity.Name);
            }
            else
            {
                albumId = model.AlbumId;
            }
            var success = pictures.CreatePicture(model.Description, fileContents, albumId);

            if (!success)
            {
                return(Redirect("/NotFound"));
            }

            return(RedirectToAction("Album", "Albums", new { id = albumId }));
        }
Example #24
0
 public void CreateAlbumWithInterpret(AlbumDTO album, int interpretId)
 {
     _albumService.CreateAlbum(album, interpretId);
 }
Example #25
0
        public void Init()
        {
            _interpret1Id = 1;
            _interpret1   = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = _interpret1Id
            };

            _interpret2Id = 2;
            _interpret2   = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = _interpret2Id
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = 1,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = 2,
                Name        = "Meteora",
                Year        = 2003
            };
            _albumService.CreateAlbum(_album1, _interpret1.ID);
            _albumService.CreateAlbum(_album2, _interpret2.ID);

            _song1Id = 1;
            _song1   = new SongDTO
            {
                ID      = _song1Id,
                Name    = "Prison Song",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song2Id = 2;
            _song2   = new SongDTO
            {
                ID      = _song2Id,
                Name    = "Deer Dance",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album1Id,
                Genre   = Genre.Rock
            };

            _song3Id = 3;
            _song3   = new SongDTO
            {
                ID      = _song3Id,
                Name    = "Numb",
                Added   = new DateTime(2016, 11, 6),
                AlbumId = _album2Id,
                Genre   = Genre.Rock
            };

            _songService.CreateSong(_song1, _album1Id);
            _songService.CreateSong(_song2, _album1Id);
            _songService.CreateSong(_song3, _album2Id);

            _songReview1Id = 1;
            _songReview1   = new SongReviewDTO
            {
                ID     = _songReview1Id,
                SongId = _song1.ID,
                Note   = "Perfect album",
                Rating = 9
            };

            _songReview2Id = 2;
            _songReview2   = new SongReviewDTO
            {
                SongId = _song2.ID,
                Note   = "Not bad",
                Rating = 8,
                ID     = _songReview2Id
            };

            _songReviewService.CreateSongReview(_songReview1, _song1Id);
            _songReviewService.CreateSongReview(_songReview2, _song2Id);
        }
        public void Init()
        {
            _interpret1 = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = 1,
                IsPublic = false
            };

            _interpret2 = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = 2,
                IsPublic = false
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = 1,
                Name        = "Toxicity",
                Year        = 2001
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = 2,
                Name        = "Meteora",
                Year        = 2003
            };
            _albumService.CreateAlbum(_album1, _interpret1.ID);
            _albumService.CreateAlbum(_album2, _interpret2.ID);

            _song1Id = 1;
            _song1   = new SongDTO
            {
                ID       = _song1Id,
                Name     = "Prison Song",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album1Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _song2Id = 2;
            _song2   = new SongDTO
            {
                ID       = _song2Id,
                Name     = "Deer Dance",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album1Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _song3Id = 3;
            _song3   = new SongDTO
            {
                ID       = _song3Id,
                Name     = "Numb",
                Added    = new DateTime(2016, 11, 6),
                AlbumId  = _album2Id,
                Genre    = Genre.Rock,
                IsPublic = false
            };

            _songService.CreateSong(_song1, _album1Id);
            _songService.CreateSong(_song2, _album1Id);
            _songService.CreateSong(_song3, _album2Id);
        }
Example #27
0
        /// <summary>
        /// Creates album with artist that corresponds with given name
        /// </summary>
        /// <param name="album">album</param>
        /// <param name="artistName">artist name</param>
        public void CreateAlbumWithArtistName(AlbumDTO album, string artistName)
        {
            var artistId = artistService.GetArtistIdByName(artistName);

            albumService.CreateAlbum(album);
        }
Example #28
0
        public void Init()
        {
            _interpret1Id = 1;
            _interpret1   = new InterpretDTO
            {
                Name     = "System of a down",
                Language = Language.English,
                ID       = _interpret1Id
            };

            _interpret2Id = 2;
            _interpret2   = new InterpretDTO
            {
                Name     = "Linkin Park",
                Language = Language.English,
                ID       = _interpret2Id
            };

            _interpretService.CreateInterpret(_interpret1);
            _interpretService.CreateInterpret(_interpret2);

            _album1Id = 1;
            _album1   = new AlbumDTO
            {
                ID          = _album1Id,
                InterpretId = _interpret1Id,
                Name        = "Toxicity",
                Year        = 2003
            };

            _album2Id = 2;
            _album2   = new AlbumDTO
            {
                ID          = _album2Id,
                InterpretId = _interpret2Id,
                Name        = "Meteora",
                Year        = 2008
            };

            _albumService.CreateAlbum(_album1, _interpret1Id);
            _albumService.CreateAlbum(_album2, _interpret2Id);

            _albumReview1Id = 1;
            _albumReview1   = new AlbumReviewDTO
            {
                ID      = _albumReview1Id,
                AlbumId = _album1.ID,
                Note    = "Perfect album",
                Rating  = 9
            };

            _albumReview2Id = 2;
            _albumReview2   = new AlbumReviewDTO
            {
                AlbumId = _album2.ID,
                Note    = "Not bad",
                Rating  = 8,
                ID      = _albumReview2Id
            };

            _albumReviewService.CreateAlbumReview(_albumReview1, _album1Id);
            _albumReviewService.CreateAlbumReview(_albumReview2, _album2Id);
        }
Example #29
0
 public Task <Album> Post([FromBody] Album album)
 {
     return(_albumService.CreateAlbum(album));
 }
Example #30
0
        public HttpResponseMessage Move([FromBody] MovePhotosViewModel viewModel)
        {
            if (viewModel == null || string.IsNullOrEmpty(viewModel.AlbumName) || !viewModel.PhotosId.Any())
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Uknown error"));
            }

            var uploadFileInfos = new List <UploadResultViewModel>();

            try
            {
                int albumId;

                try
                {
                    albumId = _albumService.GetAlbumId(User.Id, viewModel.AlbumName);
                }
                catch (AlbumNotFoundException)
                {
                    albumId = _albumService.CreateAlbum(User.Id, viewModel.AlbumName).Id;
                }

                // Get temporary album Id
                int tempAlbumId = _albumService.GetAlbumId(User.Id, "Temporary");

                // Get path to the temporary album folder
                string pathToTempAlbum = _pathUtil.BuildAbsoluteAlbumPath(User.Id, tempAlbumId);

                // Get path to the destination album folder
                string pathToDestAlbum = _pathUtil.BuildAbsoluteAlbumPath(User.Id, albumId);

                if (!_directoryWrapper.Exists(pathToDestAlbum))
                {
                    _directoryWrapper.CreateDirectory(pathToDestAlbum);
                }

                foreach (int photoId in viewModel.PhotosId)
                {
                    PhotoModel photoModel = _photoService.GetPhoto(User.Id, photoId);

                    string fileInTempAlbum = string.Format("{0}\\{1}.{2}", pathToTempAlbum, photoModel.Id,
                                                           photoModel.Format);

                    string fileInDestAlbum = string.Format("{0}\\{1}.{2}", pathToDestAlbum, photoModel.Id,
                                                           photoModel.Format);

                    bool fileExist = _fileWrapper.Exists(fileInTempAlbum);

                    if (fileExist)
                    {
                        try
                        {
                            _fileWrapper.Move(fileInTempAlbum, fileInDestAlbum);
                        }
                        catch (Exception)
                        {
                            uploadFileInfos.Add(new UploadResultViewModel
                            {
                                Id         = photoId,
                                IsAccepted = false,
                                Error      = "Can't save photo to selected album"
                            });

                            continue;
                        }

                        photoModel.AlbumId = albumId;

                        _photoService.UpdatePhoto(photoModel);

                        // Create thumbnails for photo
                        _photoProcessor.CreateThumbnails(User.Id, albumId, photoModel.Id, photoModel.Format);

                        uploadFileInfos.Add(new UploadResultViewModel
                        {
                            Id         = photoId,
                            IsAccepted = true
                        });
                    }
                    else
                    {
                        uploadFileInfos.Add(new UploadResultViewModel
                        {
                            Id         = photoId,
                            IsAccepted = false,
                            Error      = "Photo is not found in temporary album"
                        });
                    }
                }

                // Create collage for album
                _collageProcessor.CreateCollage(User.Id, albumId);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, uploadFileInfos, new JsonMediaTypeFormatter()));
        }