public Model.Users Insert(UsersInsertRequest request) { var entity = _mapper.Map <Database.Users>(request); if (request.Password != request.PasswordConfirmation) { throw new UserException("Passwords don't match!"); } entity.PasswordSalt = GenerateSalt(); entity.PasswordHash = GenerateHash(entity.PasswordSalt, request.Password); _context.Users.Add(entity); _context.SaveChanges(); foreach (var userTypes in request.UserTypes) { _context.UsersUserTypes.Add(new Database.UsersUserTypes() { UserId = entity.Id, UserTypeId = userTypes, ModifiedDate = DateTime.Now, IsActive = true }); } _context.SaveChanges(); return(_mapper.Map <Model.Users>(entity)); }
public void Delete(int id) { var entity = _context.Reviews.Find(id); _context.Reviews.Remove(entity); _context.SaveChanges(); }