public bool Buy(ngUserModel user, int day, string foodId, decimal val) { bool res = false; /* ExcelTable excelTable = ExcelManager.Inst.Doc.GetExcelTable(day); ExcelRow row = excelTable.GetRowByFoodId(foodId); ExcelCell cell = row.EnsureCell(user.Column); decimal prevVal = cell.Value; cell.Value = val; */ bool isNewFood = true; List<ngOrderEntry> orders = GetOrders(user, day); foreach (ngOrderEntry order in orders) { if (order.FoodId.Equals(foodId, StringComparison.OrdinalIgnoreCase)) { order.Count = val; isNewFood = false; } } if (isNewFood) { ngOrderEntry item = new ngOrderEntry(); item.Count = val; item.FoodId = foodId; orders.Add(item); } List<ngOrderEntry> newOrders = ApiUtils.AddContainersToFood(user, day, orders); if (BatchCellUpdater.Update(user, day, newOrders)) { res = true; } return res; }
public static bool Update(ngUserModel user, int day, List<ngOrderEntry> orders) { bool res = false; ExcelManager.Inst.RefreshAccessToken(); Dictionary<ngUserModel,List<ngOrderEntry>> items = new Dictionary<ngUserModel, List<ngOrderEntry>>(); items.Add(user,orders); res = Update(day,items); return res; }
internal decimal CalcTotal(ngUserModel user, int day) { List<ngOrderEntry> orders = GetOrders(user, day); decimal res = 0; foreach (ngOrderEntry item in orders) { ngFoodItem food = FoodManager.Inst.GetFoodById(item.FoodId); res += item.Count*food.Price; } return res; }
public List<ngHistoryEntry> MakePropousal(ngUserModel user, int dayOfWeek) { List<ngHistoryEntry> res = new List<ngHistoryEntry>(); ngHistoryModel history = HistoryManager.Inst.GetHistoryModelByUser(user); if (null != history) { List<List<ngHistoryEntry>> groups = FindPossibleMenus(dayOfWeek, history); if (groups.Count > 0) { groups = groups.OrderByDescending(g => g.Count).ToList(); int randomNumber = _random.Next(groups.Count); res = groups[randomNumber]; } } return res; }
public List<ngOrderEntry> GetOrders(ngUserModel user, int day) { List<ngOrderEntry> res = new List<ngOrderEntry>(); ExcelTable excelTable = ExcelManager.Inst.Doc.GetExcelTable(day); if (null != excelTable) { List<ExcelRow> rows = excelTable.Rows; foreach (ExcelRow row in rows) { ExcelCell cell = row.GetCell(user.Column); if (cell != null && row.HasPrice && cell.Value > 0) { ngOrderEntry item = new ngOrderEntry(); item.Count = cell.Value; item.FoodId = row.GetFoodId(); res.Add(item); } } } return res; }
private static void AddHistoryEntryToModel(ngUserModel ngUser, List<ngOrderEntry> orders, int dayOfWeek) { ngHistoryModel model = HistoryManager.Inst.GetHistoryModelByUser(ngUser); if (null == model) { model = new ngHistoryModel(); HistoryManager.Inst.AddItemAndSave(model); model.Email = ngUser.Email; model.UserId = ngUser.Id; model.Entries = new List<ngHistoryEntry>(); } foreach (ngOrderEntry ngOrderModel in orders) { ngHistoryEntry entry = new ngHistoryEntry(); entry.Date = DateTime.Now; entry.FoodId = ngOrderModel.FoodId; entry.Count = ngOrderModel.Count; ngFoodItem food = FoodManager.Inst.GetFoodById(dayOfWeek, ngOrderModel.FoodId); entry.FoodPrice = food.Price; model.Entries.Add(entry); } }
internal bool ChangePrice(ngUserModel user, int day, string foodId, decimal val) { bool res = true; ExcelTable excelTable = ExcelManager.Inst.Doc.GetExcelTable(day); ExcelRow row = excelTable.GetRowByFoodId(foodId); ExcelCell cell = row.EnsureCell(ColumnNames.Price); decimal prevVal = cell.Value; cell.Value = val; //request update cell res = false; return res; }
internal bool Delete(ngUserModel user, int day, string foodId) { bool res = false; /* ExcelTable excelTable = ExcelManager.Inst.Doc.GetExcelTable(day); ExcelRow row = excelTable.GetRowByFoodId(foodId); ExcelCell cell = row.GetCell(user.Column); cell.Value = 0; * */ List<ngOrderEntry> orders = GetOrders(user, day); foreach (ngOrderEntry order in orders) { if (order.FoodId.Equals(foodId, StringComparison.OrdinalIgnoreCase)) { order.Count = 0; } } /* List<ngOrderEntry> oldOrders = GetOrders(user, day); oldOrders.Add(deletedOrder); */ List<ngOrderEntry> newOrders = ApiUtils.AddContainersToFood(user, day, orders); if (BatchCellUpdater.Update(user, day, newOrders)) { res = true; } return res; }
public string GetOrderId(ngUserModel user, int day) { string res = "user:"******" dayofweek:" + day + " date:" + DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day; return res; }
internal List<ngFoodItem> GetOrderedFoods(ngUserModel user, int day) { List<ngFoodItem> res = new List<ngFoodItem>(); List<ngOrderEntry> orders = GetOrders(user, day); foreach (ngOrderEntry order in orders) { ngFoodItem ngFoodItem = FoodManager.Inst.GetFoodById(day, order.FoodId); res.Add(ngFoodItem); } return res; }