public async Task AddPitchAsync(CreatePitchCommand command) { var pitch = new Pitch(command.Name, command.Surface, command.Lightning, command.Street, command.City); await _context.Pitches.AddAsync(pitch); await _context.SaveChangesAsync(); }
public async Task AddContactMessageAsync(CreateContactMessageCommand command) { var contactmessage = new ContactMessage(command.Name, command.Email, command.Text); await _context.ContactMessages.AddAsync(contactmessage); await _context.SaveChangesAsync(); }
public async Task DeleteAsync(int id) { var image = await _context.PitchImages.SingleOrDefaultAsync(x => x.Id == id); if (image == null) { throw new CorruptedOperationException("Image doesn't exist."); } _context.PitchImages.Remove(image); await _context.SaveChangesAsync(); }
public async Task ChangePasswordAsync(int id, UpdateAccount command) { var account = await GetAsync(id); _passwordManager.CalculatePasswordHash(command.NewPassword, out byte[] passwordHash, account.Salt); account.Update(account.Name, account.Surname, passwordHash); await _context.SaveChangesAsync(); }
public async Task AddAsync(CreateReservation command, Captain captain, Pitch pitch) { var reservation = new Reservation(command.Name, command.StartDate, command.EndDate); if (_context.Reservations.Where(x => x.Pitch.Id == pitch.Id).Any(y => reservation.IsOverlaping(y)) == true) { throw new CorruptedOperationException("Rezerwacja na tym boisku w podanym okresie już istnieje! Sprawdź wszystkie rezerwacje w widoku boiska."); } if (captain.Reservations.Where(x => x.StartDate.Date == command.StartDate.Date).Count() >= 2) { throw new CorruptedOperationException("Maksymalna ilość rezerwacji na dzień to: 2."); } reservation.Pitch = pitch; reservation.Captain = captain; await _context.Reservations.AddAsync(reservation); await _context.SaveChangesAsync(); }
public async Task CreateMessageAsync(CreateMessage command, Account account) { var message = new Message { Content = command.Content }; await _context.Messages.AddAsync(message); account.Messages.Add(message); await _context.SaveChangesAsync(); }
public async Task CreateCommentAsync(CreateCommentCommand command, Account account, Pitch pitch) { var comment = new Comment { Content = command.Content }; account.Comments.Add(comment); pitch.Comments.Add(comment); await _context.Comments.AddAsync(comment); await _context.SaveChangesAsync(); }
public async Task AddAsync(int parentId, IFormFile image) { var account = await _accountService.GetAsync(parentId); var buffer = new byte[image.Length]; image.OpenReadStream().Read(buffer, 0, (int)image.Length); var img = new AccountImage(buffer, image.ContentType); account.AccountImage = img; await _context.SaveChangesAsync(); }
public async Task AddAsync(CreateAccount command) { if (await _context.Users.ExistsInDatabaseAsync(command.Login, command.Email)) { throw new CorruptedOperationException("User already exists."); } _passwordManager.CalculatePasswordHash(command.Password, out byte[] passwordHash, out byte[] salt); var user = new User(command.Name, command.Surname, command.Login, command.Email, salt, passwordHash); await _context.Users.AddAsync(user); await _context.SaveChangesAsync(); }
public async Task <Team> AddAsync(CreateTeam command) { if (await _context.Teams.ExistsInDatabaseAsync(command.Name)) { throw new CorruptedOperationException("Team already exists."); } var team = new Team(command.Name); await _context.Teams.AddAsync(team); await _context.SaveChangesAsync(); return(team); }
public async Task AddWIthTeamAsync(CreateCaptainWithTeam command) { byte[] salt, passwordHash; var team = await _teamService.AddAsync(command.Team); if (await _context.Captains.ExistsInDatabaseAsync(command.Login, command.Email)) { throw new CorruptedOperationException("Captain already exists."); } _passwordManager.CalculatePasswordHash(command.Password, out passwordHash, out salt); var captain = new Captain(command.Name, command.Surname, command.Login, command.Email, salt, passwordHash); team.Captain = captain; await _context.Captains.AddAsync(captain); await _context.SaveChangesAsync(); }