Esempio n. 1
0
        public async Task <IActionResult> TicketCheckOut(SaleCreateInputModel model)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var rep    = await this.context.Users.FirstOrDefaultAsync(u => u.Id == userId);


            //we`ll use it for visualization or to return the model if it is invalid
            var sale = await context
                       .Sales
                       .Include(s => s.Tickets)
                       .ThenInclude(t => t.Excursion)
                       .ThenInclude(e => e.ExcursionType)
                       .FirstOrDefaultAsync(s => s.IsFinalized == false &&
                                            s.Liquidation.RepresentativeId == rep.Id);


            model.IsInvalid = model.TotalAccumulated != model.TotalSumAfterDiscount;
            if (model.IsInvalid)
            {
                model.IsInvalid    = true;
                model.TicketsViews = sale.Tickets.Select(t => new SaleCreateTicketViewModel
                {
                    TicketId      = t.Id,
                    AdultCount    = t.AdultCount,
                    ChildCount    = t.ChildrenCount,
                    ExcursionName = t.Excursion.ExcursionType.Name,
                    PricePerAdult = t.Excursion.PricePerAdult,
                    PricePerChild = t.Excursion.PricePerChild,
                    Discount      = t.Discount,
                })
                                     .ToList();

                return(this.View(model));
            }

            sale.Cash        = model.Cash;
            sale.CreditCard  = model.CreditCard;
            sale.TotalPrice  = model.TotalSumAfterDiscount;
            sale.IsFinalized = true;
            await context.SaveChangesAsync();

            //todo: implement this... but its not a priority!
            SaleReceiptFormView modelView = new SaleReceiptFormView()
            {
            };

            return(View("/Areas/Finance/Views/Sales/ReceiptForm.cshtml", modelView));
        }
Esempio n. 2
0
        public async Task <IActionResult> TicketCheckOut(TicketCreateInputModel model)
        {
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var rep    = await this.context.Users.FirstOrDefaultAsync(u => u.Id == userId);

            //these 3 are indeed necessary!
            var sale = await context
                       .Sales
                       .Include(s => s.Tickets)
                       .ThenInclude(t => t.Excursion)
                       .ThenInclude(e => e.ExcursionType)
                       .FirstOrDefaultAsync(s => s.IsFinalized == false &&
                                            s.Liquidation.RepresentativeId == rep.Id);


            var inputModel = new SaleCreateInputModel()
            {
                SaleId = sale.Id
            };

            inputModel.TicketsViews = sale.Tickets.Select(t => new SaleCreateTicketViewModel
            {
                TicketId      = t.Id,
                AdultCount    = t.AdultCount,
                ChildCount    = t.ChildrenCount,
                ExcursionName = t.Excursion.ExcursionType.Name,
                PricePerAdult = t.Excursion.PricePerAdult,
                PricePerChild = t.Excursion.PricePerChild,
                Discount      = t.Discount
            })
                                      .ToList();

            inputModel.TotalSumAfterDiscount = inputModel.TicketsViews.Any() ? inputModel.TicketsViews.Sum(t => t.TotalSum) : 0;

            return(View(inputModel));
        }