public IActionResult EditShift([FromBody] CashRegisterCashier cashRegisterCashier) { if (_cashRegisterCashierRepository.EditShift(cashRegisterCashier)) { return(Ok()); } return(BadRequest()); }
public IActionResult DeleteShift([FromBody] CashRegisterCashier cashRegisterCashier) { if (_cashRegisterCashierRepository.DeleteShift(cashRegisterCashier.CashierId, cashRegisterCashier.CashRegisterId)) { return(Ok()); } return(BadRequest()); }
public bool EditShift(CashRegisterCashier editedCashRegisterCashier) { var shiftInQuestion = _findShift(_dbCashierRegisterContext, editedCashRegisterCashier.CashierId, editedCashRegisterCashier.CashRegisterId); if (shiftInQuestion == null) { throw new Exception("There is no shift with given ID's"); } shiftInQuestion.StartOfShift = editedCashRegisterCashier.StartOfShift; shiftInQuestion.EndOfShift = editedCashRegisterCashier.EndOfShift; _dbCashierRegisterContext.SaveChanges(); return(true); }
public bool StartShift(int cashierId, int cashRegisterId) { var cashierWithId = _dbCashierRegisterContext.Cashiers.First(cashier => cashier.Id == cashierId); var cashierRegisterWithId = _dbCashierRegisterContext.CashRegisters.First(cashRegister => cashRegister.Id == cashRegisterId); if (cashierWithId == null || cashierRegisterWithId == null) { throw new Exception("Invalid Cashier or CashierRegister ID"); } var shift = new CashRegisterCashier { CashRegisterId = cashRegisterId, CashRegister = cashierRegisterWithId, CashierId = cashierId, Cashier = cashierWithId, StartOfShift = DateTime.Now }; _dbCashierRegisterContext.CashRegisterCashiers.Add(shift); _dbCashierRegisterContext.SaveChanges(); return(true); }
public IActionResult StartShift([FromBody] CashRegisterCashier cashRegisterCashier) { _cashRegisterCashierRepository.StartShift(cashRegisterCashier.CashierId, cashRegisterCashier.CashRegisterId); return(Ok()); }
public static void Seed(CashierRegisterContext dbContext) { var receiptCount = dbContext.Receipts.Count(); if (receiptCount != 0) { return; } var cashRegisterWithId = dbContext.CashRegisters.Find(1); var cashierWithId = dbContext.Cashiers.Find(1); var cashRegisterCount = dbContext.CashRegisterCashiers.Count(); CashRegisterCashier cashRegisterCashier; if (cashRegisterCount == 0) { var newCashRegisterCashier = new CashRegisterCashier { Cashier = cashierWithId, CashierId = cashierWithId.Id, CashRegister = cashRegisterWithId, CashRegisterId = cashRegisterWithId.Id, StartOfShift = DateTime.Now }; dbContext.Add(newCashRegisterCashier); dbContext.SaveChanges(); cashRegisterCashier = newCashRegisterCashier; } else { cashRegisterCashier = dbContext.CashRegisterCashiers.First(); } var allProducts = dbContext.Products.ToList(); for (var receiptIndex = 0; receiptIndex < 10; receiptIndex++) { var receipt = new Receipt { Id = new Guid(), DateTimeCreated = DateTime.Now, CashRegisterCashier = cashRegisterCashier }; dbContext.Add(receipt); dbContext.SaveChanges(); var productsOnReceipt = new List <Product>(); var productIndexes = new List <int>(); do { var randomIndex = new Random().Next(1, allProducts.Count); var any = productIndexes.Any(index => index == randomIndex); if (!any) { productIndexes.Add(randomIndex); } } while (productIndexes.Count < 3); foreach (var productIndex in productIndexes) { productsOnReceipt.Add(allProducts[productIndex]); } var receiptProductList = new List <ReceiptProduct>(); foreach (var product in productsOnReceipt) { var newReceiptProduct = new ReceiptProduct { Product = product, ProductId = product.Id, Receipt = receipt, ReceiptId = receipt.Id, ProductCount = 5, ProductDirectPercentageAtCreation = dbContext.Taxes.Single(tax => tax.TaxType == TaxType.Direct && tax.ProductTaxes.Any(prd => prd.ProductId == product.Id)) .Percentage, ProductExcisePercentageAtCreation = dbContext.Taxes.Single(tax => tax.TaxType == TaxType.Excise && tax.ProductTaxes.Any(prd => prd.ProductId == product.Id)) .Percentage, ProductPriceAtCreation = product.Price }; receiptProductList.Add(newReceiptProduct); dbContext.ReceiptProducts.Add(newReceiptProduct); dbContext.SaveChanges(); product.CountInStorage -= 5; dbContext.SaveChanges(); } var preTaxTotal = receiptProductList.Sum(product => product.Product.Price * product.ProductCount); var exciseTotal = receiptProductList.Sum(product => product.Product.Price * dbContext.Taxes.Single(tax => tax.TaxType == TaxType.Excise && tax.ProductTaxes.Any(prd => prd.ProductId == product.Product.Id)).Percentage / 100 * product.ProductCount); var directTotal = receiptProductList.Sum(product => product.Product.Price * dbContext.Taxes.Single(tax => tax.TaxType == TaxType.Direct && tax.ProductTaxes.Any(prd => prd.ProductId == product.Product.Id)).Percentage / 100 * product.ProductCount); var postTaxTotal = preTaxTotal + exciseTotal + directTotal; if (preTaxTotal != null) { receipt.PreTaxPriceAtCreation = (int)preTaxTotal; } if (exciseTotal != null) { receipt.ExciseTaxAtCreation = (int)exciseTotal; } if (directTotal != null) { receipt.DirectTaxAtCreation = (int)directTotal; } if (postTaxTotal != null) { receipt.PostTaxPriceAtCreation = (int)postTaxTotal; } dbContext.SaveChanges(); } }