public Model.Users Insert(UsersInsertRequest request) { var entity = _mapper.Map <Database.Users>(request); if (request.Password != request.PasswordConfirmation) { throw new UserException("Passwords do not match"); } if (CheckUsernameExists(request.Username)) { throw new UserException("Username is already taken."); } if (CheckEmailExists(request.Email)) { throw new UserException("Email is already taken."); } entity.PasswordSalt = GenerateSalt(); entity.PasswordHash = GenerateHash(entity.PasswordSalt, request.Password); entity.RoleId = _context.Roles.Where(x => x.Name == "User").FirstOrDefault().Id; entity.DateRegistered = DateTime.Now; _context.Users.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Users>(entity)); }
public Model.Notations GetById(int id) { var entity = _context.Notations.Where(x => x.Id == id) .Include(x => x.Song.Album) .Include(x => x.Song.Artist) .Include(x => x.Song.Genre) .Include(x => x.User) .Include(x => x.LastEditor) .FirstOrDefault(); if (entity != null) { NotationViews view = new NotationViews { NotationId = entity.Id, Timestamp = DateTime.Now }; _context.NotationViews.Add(view); _context.SaveChanges(); } var notation = _mapper.Map <Model.Notations>(entity); IncludeNotationStats(notation); return(notation); }
public Model.NotationCorrections Insert(NotationCorrectionsInsertRequest request) { var entity = _mapper.Map <Database.NotationCorrections>(request); entity.Status = ReviewStatus.Pending; entity.UserId = _usersService.GetCurrentUser().Id; entity.DateSubmitted = DateTime.Now; _context.NotationCorrections.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.NotationCorrections>(entity)); }
public bool Delete(int id) { Database.Favorites entity = _context.Favorites .Where(x => x.NotationId == id) .Where(x => x.UserId == _usersService.GetCurrentUser().Id) .FirstOrDefault(); if (entity != null) { _context.Favorites.Remove(entity); _context.SaveChanges(); return(true); } return(false); }
public Model.Songs Insert(SongsInsertRequest request) { var entity = _mapper.Map <Database.Songs>(request); if (_usersService.GetCurrentUser().Role.Name == "Administrator") { entity.Status = ReviewStatus.Approved; } else { entity.Status = ReviewStatus.Pending; } _context.Songs.Add(entity); _context.SaveChanges(); return(_mapper.Map <Model.Songs>(entity)); }
public Model.Ratings RateNotation(RatingsInsertRequest request) { int UserId = _usersService.GetCurrentUser().Id; Database.Ratings entity = _context.Ratings.Where(x => x.NotationId == request.NotationId && x.UserId == UserId).FirstOrDefault(); if (entity != null) { entity.Rating = request.Rating; } else { entity = _mapper.Map <Database.Ratings>(request); entity.UserId = UserId; _context.Ratings.Add(entity); } _context.SaveChanges(); return(_mapper.Map <Model.Ratings>(entity)); }