Example #1
0
        public async Task <IActionResult> Put(bool active)
        {
            _logger.LogInformation("Delete All Order");

            var dbActive = _formularActiveRepo.isActive();

            dbActive.Result.Active = active;

            await _context.SaveChangesAsync();

            return(Ok());
        }
Example #2
0
        public async Task <ActionResult> Post(ViewModelOrder order)
        {
            _logger.LogInformation("Post Order", order);

            if (ModelState.IsValid && order.Botfield == null)
            {
                var findClient = await _clientRepo.ClientFindByEmail(order.Email);

                if (findClient == null)
                {
                    findClient = await _clientRepo.CreateClient(new Clients()
                    {
                        Email     = order.Email,
                        Phone     = order.Phone,
                        LastName  = order.ClientLastName,
                        FirstName = order.ClientFirstName
                    });

                    var createKadett = await _kadettRepo.CreateKadett(new Kadett()
                    {
                        LastName      = order.KadettLastName,
                        FirstName     = order.KadettFirstName,
                        KadettInKader = order.KadettInKader
                    });

                    var createOrder = await _orderRepo.CreateOrder(new Orders()
                    {
                        Bemerkung = order.Bemerkung,
                        OrderDate = DateTime.Now,
                        Client    = findClient,
                        Kadett    = createKadett
                    });

                    foreach (var ticket in order.Tickets)
                    {
                        Ticket ticketMatch = await _ticketRepo.GetByType(ticket.Type);

                        if (ticketMatch == null)
                        {
                            return(BadRequest());
                        }

                        var ticketOrder = await _ticketOrderRepo.CreateTicketOrder(new TicketOrder()
                        {
                            Order    = createOrder,
                            Ticket   = ticketMatch,
                            Quantity = ticket.Quantity,
                            Day      = ticket.Day
                        });
                    }
                    var email = await _clientRepo.ClientFindByEmail(order.Email);

                    if (email == null)
                    {
                        await _context.SaveChangesAsync();

                        if (!HostingEnvironment.IsDevelopment())
                        {
                            await _emailSenderService.SendEmailAsync(order.Email);
                        }
                        return(Ok());
                    }
                }
                return(Conflict());
            }
            return(ValidationProblem());
        }