public IHttpResponse Details(int id)
        {
            var user = this.db.Users.FirstOrDefault(u => u.Username == this.User.Username);

            if (user == null)
            {
                return(this.BadRequestError("Invalid user!"));
            }

            var receipt = this.db.Receipts
                          .Where(u => u.Recipient.Username == user.Username)
                          .FirstOrDefault(r => r.Id == id);

            if (receipt == null)
            {
                return(this.BadRequestError("Invalid receipt id!"));
            }

            var total = (decimal)receipt.Package.Weight * (decimal)2.67;

            var receiptDetailsViewModel = new ReceiptDetailsViewModel
            {
                Id                 = receipt.Id,
                IssuedOn           = receipt.IssuedOn.ToShortDateString(),
                DeliveryAddress    = receipt.Package.ShippingAddress,
                PackageWeight      = receipt.Package.Weight,
                PackageDescription = receipt.Package.Description,
                Recipient          = receipt.Recipient.Username,
                Total              = total
            };

            return(this.View(receiptDetailsViewModel));
        }
예제 #2
0
        public IHttpResponse Details(int id)
        {
            var receipt = this.DbContext.Receipts.FirstOrDefault(r => r.Id == id);

            if (receipt == null)
            {
                return(this.BadRequestErrorWithView($"Receipt with id {id} not found"));
            }

            if (receipt.Recipient.Username != this.User.Username)
            {
                return(this.BadRequestError("You are not the owner of that receipt."));
            }

            var viewModel = new ReceiptDetailsViewModel
            {
                ReceiptNumber      = receipt.Id,
                IssueDate          = receipt.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                DeliveryAddress    = receipt.Package.ShippingAddress,
                PackageWeight      = receipt.Package.Weight,
                PackageDescription = receipt.Package.Description,
                Recipient          = receipt.Recipient.Username,
                Total = receipt.Fee,
            };

            return(this.View(viewModel));
        }
예제 #3
0
        public IHttpResponse Create()
        {
            var orders = Db.Orders.Where(o => o.Status == Status.Active).ToList();

            orders.ForEach(o => o.Status = Status.Completed);

            var receipt = new Receipt
            {
                Cashier  = Db.Users.Single(c => c.Username.Equals(User.Username)),
                IssuedOn = DateTime.UtcNow
            };

            Db.Orders.UpdateRange(orders);
            Db.SaveChanges();

            Db.Receipts.Add(receipt);
            Db.SaveChanges();

            var receiptOrder = new ReceiptOrder
            {
                Orders  = orders,
                Receipt = receipt
            };

            Db.ReceiptOrders.Add(receiptOrder);
            Db.SaveChanges();

            var userReceipt = new UserReceipt
            {
                Receipt = receipt,
                Cashier = receipt.Cashier
            };

            Db.UserReceipts.Add(userReceipt);
            Db.SaveChanges();

            var orderViewModels = receiptOrder.Orders
                                  .Select(o => new OrderViewModel
            {
                Id       = o.Id,
                Product  = o.Product.Name,
                Quantity = o.Quantity,
                Price    = o.Product.Price
            })
                                  .ToList();

            var receiptViewModel = new ReceiptDetailsViewModel
            {
                Id       = receipt.Id,
                Orders   = orderViewModels,
                IssuedOn = receipt.IssuedOn.ToString("dd/MM/yyyy"),
                Cashier  = receipt.Cashier.Username
            };

            var total = orderViewModels.Sum(ovm => ovm.Quantity * ovm.Price);

            receiptViewModel.Total = total;

            return(View("/receipts/details", receiptViewModel));
        }
예제 #4
0
        public IActionResult All()
        {
            List <Receipt> receipts = this._context.Receipts
                                      .Where(a => a.RecipientId == _userManager.GetUserId(User))
                                      .Include(a => a.Package)
                                      .Include(a => a.Recipient)
                                      .ToList();

            ReceiptsAllViewModel viewModel = new ReceiptsAllViewModel();

            foreach (var r in receipts)
            {
                ReceiptDetailsViewModel model = new ReceiptDetailsViewModel
                {
                    Fee             = r.Fee,
                    Id              = r.Id,
                    ShippingAddress = r.Package.ShippingAddress,
                    Description     = r.Package.ShippingAddress,
                    PackageWeight   = r.Package.Weight,
                    IssuedOn        = r.IssuedOn,
                    RecipientName   = r.Recipient.UserName
                };
                viewModel.Receipts.Add(model);
            }
            return(View(viewModel));
        }
        public IHttpResponse Details(int id)
        {
            var receipt = this.Db.Receipts.FirstOrDefault(r => r.Id == id);

            if (receipt == null)
            {
                return(this.BadRequestError("Receipt with id do not exist."));
            }

            if (receipt.RecipientId.ToString() != this.User.Info)
            {
                return(this.BadRequestError("You do not have rights to view this detail view."));
            }


            var model = new ReceiptDetailsViewModel()
            {
                Id          = receipt.Id,
                Address     = receipt.Package.ShippingAddress,
                Description = receipt.Package.Description,
                Fee         = receipt.Fee,
                IssuedOn    = receipt.IssuedOn.ToShortDateString(),
                Recipient   = receipt.Recipient.Username,
                Weight      = receipt.Package.Weight.ToString()
            };

            return(this.View(model));
        }
        public async Task <IActionResult> Details(string id)
        {
            Receipt receiptFromDb = this._receiptsService
                                    .GetAllReceiptsWithRecipientAndPackage()
                                    .Where(receipt => receipt.Id == id)
                                    .SingleOrDefault();

            if (receiptFromDb == null)
            {
                this._logger.LogWarning($"Receipt with id {id} - NOT FOUND");
                return(this.NotFound());
            }

            ReceiptDetailsViewModel viewModel = new ReceiptDetailsViewModel
            {
                Id        = receiptFromDb.Id,
                Total     = receiptFromDb.Fee,
                Recipient = receiptFromDb.Recipient.FirstName +
                            receiptFromDb.Recipient.LastName.Substring(0, 1),

                //TODO - simplify
                DeliveryAddress = this._addressesService
                                  .ShortenedAddressToString(
                    await this._addressesService
                    .GetAddressByIdAsync(receiptFromDb
                                         .Package.ShippingAddress)),
                /////////////////////////////////////////////////////////////
                PackageWeight      = receiptFromDb.Package.Weight,
                PackageDescription = receiptFromDb.Package.Description,
                IssuedOn           = receiptFromDb.IssuedOn
                                     .ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
            };

            return(this.View(viewModel));
        }
        public IActionResult Details(int id)
        {
            var receipt = this.context.Receipts.FirstOrDefault(x => x.Id == id);
            var package = this.context.Packages
                          .Include(x => x.Receipt)
                          .ThenInclude(x => x.Recipient)
                          .FirstOrDefault(x => x.Receipt.Id == id);

            //var recipient = this.context.Users.FirstOrDefault(x => x.Id == package.RecipientId);
            if (receipt != null && package != null)
            {
                var detailsModel = new ReceiptDetailsViewModel
                {
                    DeliveryAddress    = package.ShippingAddress,
                    IssuedOn           = receipt.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                    PackageDescription = package.Description,
                    PackageWeight      = package.Weight,
                    ReceiptNumber      = receipt.Id,
                    Recipient          = package.Recipient.UserName,
                    Total = receipt.Fee
                };

                return(this.View(detailsModel));
            }
            return(this.View());
        }
        public IActionResult Details(string id)
        {
            //TODO SECURE
            var receipt =
                this.dbService.Db().Receipts.Include(r => r.Recipient).FirstOrDefault(r => r.Id == id && r.Recipient.NormalizedUserName == this.User.Identity.Name.ToUpper());

            if (receipt == null)
            {
                return(BadRequest("Invalid receipt."));
            }

            var package   = this.dbService.Db().Packages.FirstOrDefault(x => x.Id == receipt.PackageId);
            var viewModel = new ReceiptDetailsViewModel()
            {
                DeliveryAddress = package.ShippingAddress,
                Description     = package.Description,
                Recipient       = receipt.Recipient.UserName,
                Id       = receipt.Id,
                Weight   = package.Weight,
                IssuedOn = receipt.IssuedOn.ToString("d"),
                Fee      = receipt.Fee
            };

            return(this.View(viewModel));
        }
예제 #9
0
        public ReceiptDetailsViewModel Get(string id, string username)
        {
            var receipt = this.context.Receipts
                          .Include(r => r.Recipient)
                          .Include(r => r.Package)
                          .FirstOrDefault(r => r.Id == id);

            if (receipt == null || receipt.Recipient.Username != username)
            {
                return(null);
            }

            var receiptModel = new ReceiptDetailsViewModel
            {
                Address            = receipt.Package.ShippingAddress,
                Fee                = receipt.Fee.ToString("F2"),
                Id                 = receipt.Id,
                IssuedOn           = receipt.IssuedOn.ToString("dd/MM/yyyy"),
                PackageDescription = receipt.Package.Description,
                PackageWeight      = receipt.Package.Weight.ToString(),
                Recipient          = receipt.Recipient.Username
            };

            return(receiptModel);
        }
        // GET: Receipts/Create
        public IActionResult QuickCreate(int orderID)
        {
            var viewModel = new ReceiptDetailsViewModel();

            viewModel.Order   = _orderManager.GetOrderByID(orderID);
            viewModel.OrderID = orderID;
            return(View(viewModel));
        }
        public IActionResult Details(string id)
        {
            var receipt = this.receiptsService.GetReceiptById(id);

            ReceiptDetailsViewModel model = this.mapper.Map <ReceiptDetailsViewModel>(receipt);

            return(this.View(model));
        }
예제 #12
0
        public async Task <IActionResult> Details(string id)
        {
            ReceiptServiceModel receiptServiceModel = await this.receiptService.GetAll()
                                                      .SingleOrDefaultAsync(receipt => receipt.Id == id);

            ReceiptDetailsViewModel receiptDetailsViewModel = receiptServiceModel.To <ReceiptDetailsViewModel>();

            return(this.View(receiptDetailsViewModel));
        }
        // GET: Receipts
        public IActionResult Index()
        {
            var viewModel = new ReceiptDetailsViewModel();
            var userID    = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            viewModel.Receipts = _receiptManager.GetAllReceipts(userID);
            viewModel.Orders   = _orderManager.GetAllOrders(userID);
            return(View(viewModel));
        }
        // GET: Receipts/Create
        public IActionResult Create()
        {
            var viewModel = new ReceiptDetailsViewModel();
            var userID    = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);

            viewModel.Orders = _orderManager.GetOrdersPendingReceipts(userID);

            return(View(viewModel));
        }
 public IActionResult Create(ReceiptDetailsViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var userID     = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
         var restaurant = _restaurantManager.GetRestaurantByUserID(userID);
         var tax        = restaurant.Tax;
         var orderID    = viewModel.OrderID;
         var order      = _orderManager.GetOrderByID(orderID);
         var receipt    = _receiptManager.CreateReceipt(order, userID, tax);
         return(RedirectToAction(nameof(Index)));
     }
     return(View(viewModel));
 }
예제 #16
0
        public IActionResult Detail(int id, ReceiptDetailsViewModel input)
        {
            string userEmail = this.User.FindFirst(ClaimTypes.Email).Value;
            var    viewModel = new ReceiptDetailsViewModel()
            {
                Id        = input.Id,
                CreatedOn = DateTime.UtcNow,
                Recipient = userEmail,
                Orders    = this.receiptsService.GetAll <ReceiptDetailsOrderViewModel>(id)
                            .ToList(),
            };

            return(this.View(viewModel));
        }
예제 #17
0
        public IActionResult Details(string id)
        {
            var receiptFromDb = this.receiptServices.GetReceiptById(id);

            var viewModel = new ReceiptDetailsViewModel
            {
                ReceiptNumber      = receiptFromDb.Id,
                IssuedOn           = receiptFromDb.IssuedOn.ToString("dd/MM/yyyy"),
                Fee                = receiptFromDb.Fee,
                DeliveryAddress    = receiptFromDb.Package.ShippingAddress,
                PackageDescription = receiptFromDb.Package.Description,
                PackageWeight      = receiptFromDb.Package.Weight,
                RecipientUserName  = receiptFromDb.Recipient.UserName
            };

            return(this.View(viewModel));
        }
        public IHttpResponse Details(string id)
        {
            var user = this.Db.Users.FirstOrDefault(x => x.Username == this.User.Username);

            if (!User.IsLoggedIn)
            {
                return(this.View("/Users/Login"));
            }
            var guidId  = new Guid(id);
            var receipt = this.Db.Receipts
                          .FirstOrDefault(x => x.Id == guidId);

            if (receipt == null)
            {
                return(this.BadRequestError("Id is not correct!"));
            }
            var orders = this.Db.Receipts
                         .Where(x => x.Id == guidId)
                         .Select(x => x.Orders.Select(y => new OrderInReceiptViewModel
            {
                Name     = y.Product.Name,
                Price    = y.Product.Price,
                Quantity = y.Quantity,
            }).ToList())
                         .FirstOrDefault();

            if (orders == null)
            {
                return(this.BadRequestError("Id is not correct!"));
            }
            var model = new ReceiptDetailsViewModel();

            model.Orders = orders;

            model.Cashier = receipt.Cashier.Username;

            if (User.Role == "User" && model.Cashier != User.Username)
            {
                return(this.BadRequestError("You can not check other users receipt`s details!"));
            }
            model.IssuedOn = receipt.IssuedOn.ToString("dd/MM/yyyy");
            model.Receipt  = receipt.Id;
            model.Total    = orders.Select(y => y.Price * y.Quantity).Sum();

            return(this.View("/Receipts/Details", model));
        }
예제 #19
0
        public ReceiptDetailsViewModel GetReceiptDetails(string orderId)
        {
            var receiptFromDb = this.context.Receipts.FirstOrDefault(x => x.OrderId == orderId);

            var receiptDetailsViewModel = new ReceiptDetailsViewModel()
            {
                OrderId         = receiptFromDb.Id,
                UserId          = receiptFromDb.UserId,
                Fee             = receiptFromDb.Fee,
                ClientName      = receiptFromDb.ClientName,
                DateOfIssue     = receiptFromDb.DateOfIssue,
                DeliveryAddress = receiptFromDb.DeliveryAddress,
                Comment         = receiptFromDb.Comment,
                Order           = receiptFromDb.Order
            };

            return(receiptDetailsViewModel);
        }
예제 #20
0
        public IActionResult Details(Guid id)
        {
            var receipt = _receiptService.GetReceiptById(id);
            var package = _packageService.GetPackageById(receipt.PackageId);

            var receiptDetails = new ReceiptDetailsViewModel()
            {
                Id                 = receipt.Id,
                IssuedOn           = receipt.IssuedOn,
                DeliveryAddress    = package.ShippingAddreess,
                PackageWeight      = package.Weight,
                PackageDescription = package.Description,
                Recipient          = User.Identity.Name,
                TotalPrice         = receipt.Fee
            };

            return(this.View(receiptDetails));
        }
예제 #21
0
        public ReceiptDetailsViewModel GetReceipt(ApplicationUser user, int id)
        {
            var receipt = user.Receipts
                          .FirstOrDefault(r => r.Id == id);

            var receiptDetails = new ReceiptDetailsViewModel()
            {
                Recipient          = receipt.Recipient.UserName,
                IssuedOn           = receipt.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                PackageWeight      = receipt.Package.Weight,
                DeliveryAddress    = receipt.Package.ShippingAddress,
                PackageDescription = receipt.Package.Description,
                ReceiptNumber      = receipt.Id,
                Total = receipt.Package.Weight * 2.67m
            };

            return(receiptDetails);
        }
        public ActionResult Create()
        {
            var orders = receiptService.ChangeOrderStatus();

            var receipt = receiptService.CreateReceipt(User.Username, orders);

            var receiptOrder = receiptService.CreateReceiptOrder(receipt, orders);

            var userReceipt = receiptService.CreateUserReceipt(receipt);

            //TODO: Fix it!!!
            //var products = productService.GetAllProducts();
            ;

            //receiptService.context.Entry(receiptOrder).Reload();

            //Thread.Sleep(3000);



            var orderViewModels = receiptOrder.Orders
                                  .Select(o => new OrderViewModel
            {
                Id       = o.Id,
                Product  = o.Product.Name,
                Quantity = o.Quantity,
                Price    = o.Product.Price
            })
                                  .ToList();

            var receiptViewModel = new ReceiptDetailsViewModel
            {
                Id       = receipt.Id,
                Orders   = orderViewModels,
                IssuedOn = receipt.IssuedOn.ToString("dd/MM/yyyy"),
                Cashier  = receipt.Cashier.Username
            };

            var total = orderViewModels.Sum(ovm => ovm.Quantity * ovm.Price);

            receiptViewModel.Total = total;

            return(View(receiptViewModel, "Details"));
        }
예제 #23
0
        public IActionResult Details(string id)
        {
            var receipt = this.dbContext.Receipts
                          .Include(r => r.Recipient)
                          .Include(p => p.Package)
                          .SingleOrDefault(r => r.Id == id);

            var receiptDetail = new ReceiptDetailsViewModel
            {
                Id              = id,
                Fee             = receipt.Fee,
                IssuedOn        = receipt.IssuedOn,
                Package         = receipt.Package,
                Recipient       = receipt.Recipient,
                ShippingAddress = receipt.Package.ShippingAddress,
            };

            return(this.View(receiptDetail));
        }
예제 #24
0
        public IActionResult Details(string id)
        {
            Receipt receiptFromDb = this.receiptsService.GetAllReceiptsWithRecipientAndPackage()
                                    .Where(receipt => receipt.Id == id)
                                    .SingleOrDefault();

            ReceiptDetailsViewModel viewModel = new ReceiptDetailsViewModel
            {
                Id                 = receiptFromDb.Id,
                Total              = receiptFromDb.Fee,
                Recipient          = receiptFromDb.Recipient.UserName,
                DeliveryAddress    = receiptFromDb.Package.ShippingAddress,
                PackageWeight      = receiptFromDb.Package.Weight,
                PackageDescription = receiptFromDb.Package.Description,
                IssuedOn           = receiptFromDb.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)
            };

            return(this.View(viewModel));
        }
예제 #25
0
        public IActionResult Details(string id)
        {
            Receipt receipt = this._context.Receipts
                              .Include(a => a.Package)
                              .Include(a => a.Recipient)
                              .FirstOrDefault(a => a.Id == id);
            ReceiptDetailsViewModel viewModel = new ReceiptDetailsViewModel
            {
                Id              = receipt.Id,
                IssuedOn        = receipt.IssuedOn,
                ShippingAddress = receipt.Package.ShippingAddress,
                Description     = receipt.Package.Description,
                Fee             = receipt.Fee,
                PackageWeight   = receipt.Package.Weight,
                RecipientName   = receipt.Recipient.UserName
            };

            return(this.View(viewModel));
        }
        public IActionResult Details()
        {
            var receiptId = int.Parse(this.Request.QueryData["id"].ToString());

            var receipt          = this.receiptsService.GetReceiptById(this.Identity, receiptId);
            var receiptViewModel = new ReceiptDetailsViewModel
            {
                Id       = receipt.PackageId,
                IssuedOn = receipt.IssuedOn != null?receipt.IssuedOn.Value.ToString("dd/MM/yyyy") : "N/A",
                               DeliveryAddress    = receipt.Package.ShippingAddress,
                               PackageWeight      = receipt.Package.Weight,
                               PackageDescription = receipt.Package.Description,
                               Recipient          = receipt.Recipient.Username,
                               Fee = receipt.Fee
            };

            this.Model.Data["Receipt"] = receiptViewModel;

            return(this.View());
        }
예제 #27
0
        public IActionResult ReceiptDetails(int id)
        {
            var receipt = this.receiptService.GetById(id)?.First();

            if (receipt != null)
            {
                ReceiptDetailsViewModel receiptDetailsViewModel = new ReceiptDetailsViewModel {
                    CustomerName = receipt.User.UserName,
                    NamesOfTechniciansHavingWorkedOnTheRepairTask = receipt.ExpertsHavingWorkedOnRepairTask.Select(x => x.Expert.UserName).ToArray(),
                    ReceiptId    = receipt.Id,
                    RepairTaskId = receipt.RepairTask.Id,
                    TotalRevenue = receipt.TotalPrice
                };
                return(this.View(receiptDetailsViewModel));
            }
            else
            {
                throw new ArgumentNullException(String.Format(StringConstants.TryingToRetrieveAMissingReceiptError, id));
            }
        }
예제 #28
0
        public IActionResult Details(string id)
        {
            var receiptFromDb = this.dbContext.Receipts
                                .Where(receipt => receipt.Id == id)
                                .Include(receipt => receipt.Package)
                                .Include(receipt => receipt.Recipient)
                                .SingleOrDefault();

            var viewModel = new ReceiptDetailsViewModel
            {
                Id                 = receiptFromDb.Id,
                IssuedOn           = receiptFromDb.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                DeliveryAddress    = receiptFromDb.Package.ShippingAddress,
                PackageWeight      = receiptFromDb.Package.Weight,
                PackageDescription = receiptFromDb.Package.Description,
                Recipient          = receiptFromDb.Recipient.UserName,
                Total              = receiptFromDb.Fee
            };

            return(this.View(viewModel));
        }
        public IHttpResponse Details(int id)
        {
            var user = this.Db.Users
                       .FirstOrDefault(x => x.Username == this.User.Username);

            var receipt = user.Receipts
                          .FirstOrDefault(r => r.Id == id);

            var model = new ReceiptDetailsViewModel
            {
                Id = receipt.Id,
                DeliveryAddress    = receipt.Package.ShippingAddress,
                IssuedOn           = receipt.IssuedOn.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture),
                PackageDescription = receipt.Package.Description,
                PackageWeight      = receipt.Package.Weight,
                Recipient          = receipt.Recipient.Username,
                Total = Math.Round(receipt.Fee, 2)
            };

            return(this.View(model));
        }
예제 #30
0
        public async Task <IActionResult> Details(string id)
        {
            ReceiptServiceModel receiptServiceModel = await this.receiptService.GetAll()
                                                      .SingleOrDefaultAsync(receipt => receipt.Id == id);


            ReceiptDetailsViewModel receiptDetailsViewModel = new ReceiptDetailsViewModel
            {
                Id        = receiptServiceModel.Id,
                IssuedOn  = receiptServiceModel.IssuedOn,
                Recipient = receiptServiceModel.Recipient.UserName,
                Orders    = receiptServiceModel.Orders.Select(order => new ReceiptDetailsOrderViewModel
                {
                    WineName  = order.Wine.Name,
                    WinePrice = order.Wine.Price,
                    Quantity  = order.Quantity
                }).ToList()
            };

            return(this.View(receiptDetailsViewModel));
        }