public RegularGuestDto(RegularGuest guest) { Id = guest.Id; Name = guest.Name; BirthDay = guest.BirthDay; Address = guest.Address; }
public async Task <RegularGuestDto> CreateRegularGuestAsync(RegularGuestDto dto) { RegularGuest guest = dto.ToEntity(); guest.Points = 0; guest.BirthDay = guest.BirthDay.AddHours(2); RegularGuest created = await _repository.AddRegularGuestAsync(guest); if (created == null) { throw new Exception("Regular guest already exists."); } return(new RegularGuestDto(created)); }
public async Task <RegularGuest> AddRegularGuestAsync(RegularGuest guest) { var existingGuest = await _context.RegularGuests .Where(g => g.Name == guest.Name && g.Address == guest.Address && g.BirthDay == guest.BirthDay) .SingleOrDefaultAsync(); if (existingGuest != null) { return(null); } _context.RegularGuests.Add(guest); await _context.SaveChangesAsync(); return(guest); }