public IActionResult Confirmation(int itemId, int distributorId, int quantity) { if (quantity <= 0) { quantity = 1; } var distributor = _context.Distributors.Find(distributorId); var item = _context.Items.Find(itemId); var user = _context.Users.Find(Convert.ToInt32(CookieUtil.GetCookie(Request, CookieUtil.USER_ID_KEY))); if (user == null) { return(NotFound()); } var receipt = new Receipt(); receipt.Distributor = distributor; receipt.Item = item; receipt.Tax = Math.Round((0.13 * ((item.MRP * quantity) + distributor.ShipPrice)), 2); receipt.ReceiveDate = DateTime.Now.AddDays(distributor.TimeToShip); receipt.Date = DateTime.Now; receipt.Quantity = quantity; receipt.Total = Math.Round((receipt.Tax + (item.MRP * quantity) + distributor.ShipPrice), 2); receipt.User = user; _context.Receipts.Add(receipt); _context.SaveChanges(); return(View("Confirmation", receipt)); }
public IActionResult Post(Models.Receipt receipt) { var sameName = _context.Receipts.FirstOrDefault(c => c.Id == receipt.Id); if (sameName == null) { _context.Receipts.Add(receipt); _context.SaveChanges(); return(Ok(receipt)); } else { return(BadRequest()); } }
public IActionResult Create() // creates set of Sale data per item (admin) { double[] weekFluctuation = { 0.60, 0.70, 0.70, 0.85, 0.95, 1.25, 1.4, 1, 1.05, 1, 1.25, 1.2, 1.1, 0.9, 0.9, 0.8, 0.68, 0.95, 1.05, 1.05, 1.1, 1.1, 1, 1, 1, 1, 1.15, 1.1, 1.15, 1.2, 1.2, 1.25, 1.3, 1.3, 1.25, 1.3, 1.45, 1.2, 1, 1, 0.8, 1, 0.8, 0.65, 0.55, 0.5, 2, 2, 1, 1.25, 1.7, 1.9 }; int numOfYears = 10; int barSize = 12; List <int> sales = new List <int>(); List <Item> items = _context.Items.ToList(); double rating; for (int i = 0; i < items.Count; i++) // for each item { DateTime date = new DateTime(2009, 01, 01); Item item = items[i]; int counter = 0; int numPreviousSales = 3; Queue <int> pastSales = new Queue <int>(); int startItemSale = random.Next(15, 90); pastSales.Enqueue(startItemSale); for (int j = 0; j < (numOfYears * weekFluctuation.Length); j++) // for each week in number of years { double mean = sales.Count > 0 ? sales.Average() : startItemSale; double variance = (weekFluctuation[(j % weekFluctuation.Length)] * ((rating = item.Rating) > 3 ? 1 + ((rating - 3) / 2) : ((rating - 1) / 2))); // calculate sales bool isPos = (variance >= 1); int min = Convert.ToInt32(-1 * ((barSize / 2) * (isPos ? (variance - 1) : (variance + 1)))); int max = Convert.ToInt32(variance * (barSize / 2)); int unitsSold = Convert.ToInt32(Math.Round(pastSales.Average() + (random.Next(min, max)))); unitsSold = unitsSold < 0 ? 0 : unitsSold; if (pastSales.Count >= numPreviousSales) // graph based off last amount of previous sales { pastSales.Dequeue(); } pastSales.Enqueue(unitsSold); sales.Append(unitsSold); Sale sale = new Sale() { Item = item, Units = unitsSold, Date = date }; // add sale _context.Sales.Add(sale); date = date.AddDays(7); counter++; } } _context.SaveChanges(); return(RedirectToAction("Index", "Stats")); }