public IHttpResponse Index() { var user = this.Db.Users.FirstOrDefault(u => u.Username == this.User.Username); if (user == null) { return(this.Redirect("/users/login")); } var allReceiptsModel = new AllReceiptsViewModel { Receipts = this.Db.Receipts .Include(r => r.Recipient) .Where(r => r.RecipientId == user.Id) .Select(r => new ReceiptViewModel { Id = r.Id, Fee = $"{r.Fee:f2}", IssuedOnDateString = r.IssuedOn.ToString(@"dd/MM/yyyy"), RecipientName = r.Recipient.Username }).ToList() }; return(this.View("Receipts/Index", allReceiptsModel)); }
public IHttpResponse Receipts() { var receipts = new List <ReceiptViewModel>(); if (User.Role == "User") { receipts = this.Db.Receipts .Where(x => x.Recipient.Username == User.Username) .Select(x => new ReceiptViewModel { Fee = x.Fee, Id = x.Id, IssuedOn = x.IssuedOn.ToString("dd/MM/yyyy"), Recipient = x.Recipient.Username }).ToList(); } else { receipts = this.Db.Receipts .Select(x => new ReceiptViewModel { Fee = x.Fee, Id = x.Id, IssuedOn = x.IssuedOn.ToString("dd/MM/yyyy"), Recipient = x.Recipient.Username }).ToList(); } var allReceiptsViewModel = new AllReceiptsViewModel { Receipts = receipts }; return(this.View("/Receipts/Index", allReceiptsViewModel)); }
public AllReceiptsViewModel GetAllReceipt() { var receipts = new AllReceiptsViewModel() { Receipts = this.db.Receipts .Select(x => new ReceiptViewModel() { Id = x.Id, Fee = x.Fee, IssuedOn = x.IssuedOn, RecipientName = x.Recipient.Username, }).ToList() }; return(receipts); }
public IHttpResponse All() { if (this.User.Role != "Admin") { return this.Redirect("/"); } var viewModel = new AllReceiptsViewModel(); viewModel.AllReceipts = this.Db.Receipts.Select(x => new SimpleReceiptViewModel { Id = x.Id, CashierName = x.Cashier.Username, IssuedOn = x.IssuedOn.ToString("dd/MM/yyyy"), TotalSum = x.Orders.Sum(s => s.Quantity * s.Product.Price).ToString("F2") }); return this.View(viewModel); }
public IHttpResponse Profile() { if (!this.User.IsLoggedIn) { return(this.Redirect("/")); } var viewModel = new AllReceiptsViewModel(); viewModel.AllReceipts = this.Db.Receipts.Where(x => x.Cashier.Username == this.User.Username) .Select(x => new SimpleReceiptViewModel { Id = x.Id, CashierName = x.Cashier.Username, IssuedOn = x.IssuedOn.ToString("dd/MM/yyyy"), TotalSum = x.Orders.Sum(s => s.Quantity * s.Product.Price).ToString("F2") }); return(this.View(viewModel)); }
public IHttpResponse All() { var receipts = this.Db.Receipts.ToList(); var model = new AllReceiptsViewModel(); var model1 = new AllReceiptViewModel(); foreach (var item in receipts) { model1 = new AllReceiptViewModel { Id = item.Id, Cashier = item.Cashier.Username, IssuedOn = item.IssuedOn, Total = item.Orders.Select(t => t.Total).Sum() }; model.Receipts.Add(model1); } return(View(model)); }
public IHttpResponse All() { var user = this.Db.Users.FirstOrDefault(x => x.Username == this.User.Username); if (!User.IsLoggedIn) { return(this.View("/Users/Login")); } var receipts = this.Db.Receipts.Where(x => x.Cashier == user) .Select(x => new OneReceiptsViewModel { Cashier = x.Cashier.Username, Id = x.Id.ToString(), IssuedOn = x.IssuedOn.ToString("dd/MM/yyyy"), Total = x.Orders.Select(y => y.Product.Price * y.Quantity).Sum(), }).ToList(); var model = new AllReceiptsViewModel { Receipts = receipts }; return(this.View("/Users/Profile", model)); }
public IHttpResponse Index() { var receipts = this.Db.Receipts.Select(x => new ReceiptViewModel { Id = x.Id, Fee = x.Fee, IssuedOn = x.IssuedOn, Recipient = x.Recipient.Username }).ToList(); if (receipts.Count == 0) { return(this.BadRequestError("There are no receipts")); } var model = new AllReceiptsViewModel { Receipts = receipts }; return(this.View(model)); }