コード例 #1
0
        public IActionResult Details(int id)
        {
            var orderline = _orderlineService.GetById(id);

            if (orderline == null)
            {
                return(NotFound());
            }
            return(Ok(orderline));
        }
コード例 #2
0
        public async Task <ActionResult> Return(int id)
        {
            var orderLine = await _oLService.GetById(id);

            if (orderLine == null ||
                orderLine.Order == null ||
                orderLine.Order.Customer != Guid.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)))
            {
                return(NotFound());
            }

            if (!orderLine.TicketId.HasValue)
            {
                ModelState.AddModelError("Return", "Enkel tickets kunnen geretourneerd worden!");
            }

            if (orderLine.ReturnedAt.HasValue)
            {
                ModelState.AddModelError("Return", "Ticket werd al geretourneerd!");
            }

            if (DateTime.Now.AddDays(7) >= orderLine.Ticket.Match.Start)
            {
                ModelState.AddModelError("Return", "Tickets kunnen maar tot 1 week voor de start van de match worden geretourneerd");
            }

            if (ModelState.IsValid)
            {
                orderLine.ReturnedAt = DateTime.Now;
                await _oLService.Update(orderLine);

                var ticket = await _ticketService.GetById(orderLine.TicketId.Value);

                if (ticket == null)
                {
                    ModelState.AddModelError("Return", "Fout!");
                    return(View(_mapper.Map <OrderLineVM>(orderLine)));
                }
                ticket.Valid = false;
                await _ticketService.Update(ticket);
            }

            return(View(_mapper.Map <OrderLineVM>(orderLine)));
        }