public async Task <IEnumerable <RegularGuestDto> > GetRegularGuestsAsync(string name)
        {
            var guests = await _repository.GetRegularGuestsAsync(name);

            var dtos = new List <RegularGuestDto>();

            foreach (var guest in guests)
            {
                var dto      = new RegularGuestDto(guest);
                int discount = 0;
                if (guest.Points >= 5 && guest.Points < 10)
                {
                    discount = 5;
                }
                else if (guest.Points >= 10 && guest.Points < 15)
                {
                    discount = 10;
                }
                else if (guest.Points >= 15 && guest.Points < 20)
                {
                    discount = 15;
                }
                else if (guest.Points >= 20)
                {
                    discount = 20;
                }
                dto.Discount = discount;
                dtos.Add(dto);
            }
            return(dtos);
        }
        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));
        }
Ejemplo n.º 3
0
 public async Task <ActionResult <RegularGuestDto> > CreateRegularGuest([FromBody] RegularGuestDto regularGuestDto)
 {
     if (regularGuestDto == null)
     {
         return(BadRequest("Guest data must be set!"));
     }
     try
     {
         return(Ok(await _service.CreateRegularGuestAsync(regularGuestDto)));
     }
     catch (Exception e)
     {
         return(Conflict(e.Message));
     }
 }