public static bool ReservItem(int id, int count, DateTime endDate) { ssmDataContext cont = new ssmDataContext(); item resvItem = cont.items.FirstOrDefault(b => b.id == id); if (resvItem != null) { if (resvItem.reserveCount != null && resvItem.reserveCount > 0) { if ((resvItem.reserveCount + count) <= resvItem.count) { resvItem.reserveCount = count + resvItem.reserveCount; if (resvItem.reserveEndDate < endDate) { resvItem.reserveEndDate = endDate; } } } else { resvItem.reserveCount = count; resvItem.reserveEndDate = endDate; } cont.SubmitChanges(); return(true); } return(false); }
public static object GetSalesForGiveBackList(string GUID, DateTime?buyDate) { IList <logSale> list = null; ssmDataContext db = new ssmDataContext(); int sid; list = (!string.IsNullOrEmpty(GUID)) && (int.TryParse(GUID, out sid)) ? (buyDate != null ? db.logSales.Where(b => b.isGiveBack == false && b.date.Value.Year == buyDate.Value.Year && b.date.Value.Month == buyDate.Value.Month && b.date.Value.Day == buyDate.Value.Day).ToList() : db.logSales.Where(b => b.isGiveBack == false && b.sid == sid).ToList()) : (buyDate != null ? db.logSales.Where(b => b.isGiveBack == false && b.date.Value.Year == buyDate.Value.Year && b.date.Value.Month == buyDate.Value.Month && b.date.Value.Day == buyDate.Value.Day).ToList() : db.logSales.Where(b => b.isGiveBack == false).ToList()); var resJoinBuers1 = list.Join(buyer.Cache, d => d.buyerId, c => c.id, (d, c) => new { buerName = c.name, d.buyerId, d.cash, d.date, d.id, d.isGiveBack, d.itemId, d.itemsCount, d.sellerId, d.logName, d.logBprice }); return(resJoinBuers1.OrderByDescending(ord => ord.date).ToList()); }
public static void GiveBack(int buyerId, int sellerId, int itemId, float itemsCount, float cash, int sid) { var db = new ssmDataContext(); logSale sale = db.logSales.FirstOrDefault( b => b.buyerId == buyerId && b.sellerId == sellerId && b.sid == sid && b.isGiveBack == false); if (sale != null) { sale.cash = sale.cash - cash; sale.itemsCount = sale.itemsCount - itemsCount; } var logSale = new logSale { buyerId = buyerId, sellerId = sellerId, itemId = itemId, itemsCount = itemsCount, date = DateTime.Now, isGiveBack = true, cash = cash, sid = sid }; db.logSales.InsertOnSubmit(logSale); db.SubmitChanges(); }
public static IList <item> GetAll() { var db = new ssmDataContext(); var result = AppHelper.CurrentUser.login.ToLower().Contains("admin") ? Flood() : db.items.ToList(); return(result); }
public static void Order(int id) { ssmDataContext db = new ssmDataContext(); item orderItem = db.items.FirstOrDefault(b => b.id == id); orderItem.order = true; db.SubmitChanges(); }
public static IList <item> GetAllByGroupId(int groupId) { var db = new ssmDataContext(); var groupIDs = db.groups.Where(g => g.id == groupId || g.parent == groupId).Select(g => g.id).ToList(); var result = db.items.Where(itm => groupIDs.Contains(itm.groupId.Value) && (itm.isActive.HasValue && itm.isActive.Value || (AppHelper.CurrentUser.isAdmin.HasValue && AppHelper.CurrentUser.isAdmin.Value))).ToList(); return(result); }
public static void Info(string message) { var db = new ssmDataContext(); var logActivity = new logActivity { action = message, informAdmin = false }; db.logActivities.InsertOnSubmit(logActivity); db.SubmitChanges(); }
public static void Warning(string message, int sellerId) { var db = new ssmDataContext(); var logActivity = new logActivity { action = message, SellerId = sellerId, informAdmin = true, date = DateTime.Now }; db.logActivities.InsertOnSubmit(logActivity); db.SubmitChanges(); }
public static void CheckForOrder(int id) { ssmDataContext db = new ssmDataContext(); item orderItem = db.items.FirstOrDefault(b => b.id == id); if (orderItem.count.HasValue && orderItem.countToOrder.HasValue) { orderItem.order = orderItem.count <= orderItem.countToOrder; } db.SubmitChanges(); }
public static IList <logType> GetGiveBackListForApprove() { if (AppHelper.CurrentUser.isAdmin.Value) { ssmDataContext db = new ssmDataContext(); var logSalesJoinSeller = db.logSales .Where(g => g.isGiveBack == true /// будем апрувить все возвраты /// && g.sellerId != AppHelper.CurrentUser.id && g.itemsCount != 0 ) .ToList() .Join(seller.Cache, d => d.sellerId, c => c.id, (d, c) => new { sellerName = c.fullName, d.buyerId, d.cash, d.date, d.id, d.isGiveBack, d.itemId, d.itemsCount, d.sellerId }); var logSalesJoinSellerBuyer = logSalesJoinSeller.Join(buyer.Cache, d => d.buyerId, c => c.id, (d, c) => new { buerName = c.name, d.buyerId, d.cash, d.date, d.id, d.isGiveBack, d.itemId, d.itemsCount, d.sellerId, d.sellerName }); var res = logSalesJoinSellerBuyer.Join(db.items, d => d.itemId, c => c.id, (d, c) => new logType { SellerName = d.sellerName, BuyerName = d.buerName, ProductName = c.name, LogCash = d.cash, Logdate = d.date, ItemsCount = d.itemsCount, LogIsGiveBack = d.isGiveBack, LogId = d.id }); return(res.OrderBy(f => f.Logdate).ToList()); } return(null); }
public static void CheckForExpiredItems() { var db = new ssmDataContext(); var result = db.items.Where(i => i.reserveEndDate <= DateTime.Now).ToList(); foreach (var item in result) { item.reserveCount = null; item.reserveEndDate = null; } db.SubmitChanges(); }
public static void UnReservForItemId(int id) { ssmDataContext cont = new ssmDataContext(); item resvItem = cont.items.FirstOrDefault(b => b.id == id); if (resvItem != null) { resvItem.reserveCount = null; resvItem.reserveEndDate = null; cont.SubmitChanges(); } }
/// <summary> /// Buyer refund our money /// </summary> /// <param name="buyerId">Buyer's ID</param> /// <param name="cash">Sum of refund</param> public static void Refund(int buyerId, float cash) { var db = new ssmDataContext(); buyer buyer = db.buyers.First(b => b.id == buyerId); if (buyer.debt != null) { buyer.debt -= cash; } else { buyer.debt = -cash; } db.SubmitChanges(); Refresh(); }
/// <summary> /// Buyer run into debt /// </summary> /// <param name="buyerId">Buyer's ID</param> /// <param name="cash">Sum of Sale</param> public static void RunIntoDebt(int buyerId, decimal cash) { var db = new ssmDataContext(); buyer buyer = db.buyers.First(b => b.id == buyerId); if (buyer.debt != null) { buyer.debt += (double?)cash; } else { buyer.debt = (double?)cash; } db.SubmitChanges(); Refresh(); }
private static object GetLogActivityList(IQueryable <logActivity> rootQuery, ssmDataContext db) { var logActivityJoinBuyer = rootQuery .ToList() .Join(seller.Cache, d => d.SellerId, c => c.id, (d, c) => new { sellerName = c.fullName, d.SellerId, d.action, d.date, d.id, d.informAdmin }); return(logActivityJoinBuyer.OrderBy(g => g.date).ToList()); }
private static object GetLogSalesList(IQueryable <logSale> rootQuery, ssmDataContext db) { var logSalesJoinSeller = rootQuery .ToList() .Join(seller.Cache, d => d.sellerId, c => c.id, (d, c) => new { sellerName = c.fullName, d.buyerId, d.cash, d.date, d.id, d.isGiveBack, d.itemId, d.itemsCount, d.sellerId }); var logSalesJoinSellerBuyer = logSalesJoinSeller .Join(buyer.Cache, d => d.buyerId, c => c.id, (d, c) => new { buerName = c.name, d.buyerId, d.cash, d.date, d.id, d.isGiveBack, d.itemId, d.itemsCount, d.sellerId, d.sellerName }); var res = logSalesJoinSellerBuyer .Join(db.items, d => d.itemId, c => c.id, (d, c) => new { SellerName = d.sellerName, BuyerName = d.buerName, ItemName = c.name, LogCash = d.cash, Logdate = d.date, ItemsCount = d.itemsCount, d.isGiveBack, d.id }); return(res.OrderBy(f => f.Logdate).ToList()); }
public static void ApproveGiveBack(int id) { ssmDataContext db = new ssmDataContext(); logSale log = db.logSales.FirstOrDefault(b => b.id == id); if (log != null && log.isGiveBack.Value && AppHelper.CurrentUser.isAdmin.Value) { item itm = db.items.FirstOrDefault(c => c.id == log.itemId); if (itm != null && itm.count != null) { log.sellerId = AppHelper.CurrentUser.id; itm.count += log.itemsCount; log.itemsCount = 0; db.SubmitChanges(); } } }
public static void Sale(int buyerId, int sellerId, int itemId, float itemsCount, decimal?cash, int sid) { var db = new ssmDataContext(); var logSale = new logSale { buyerId = buyerId, sellerId = sellerId, itemId = itemId, itemsCount = itemsCount, date = DateTime.Now, isGiveBack = false, cash = (double?)cash, sid = sid }; db.logSales.InsertOnSubmit(logSale); db.items.First(i => i.id == itemId).count -= itemsCount; db.SubmitChanges(); }
private static IList <item> Flood() { IList <item> result = new List <item>(); var db = new ssmDataContext(); var r = new Random(); IList <int> groups = db.groups.Select(g => g.id).ToArray(); IList <string> names = db.items.Select(i => i.name).ToList(); if (names.Count < 10) { int namesCount = r.Next(300, 400); for (int i = 0; i < namesCount; i++) { names.Add("Товар № " + i); } } for (int i = 0; i < r.Next(30, 100); i++) { result.Add( new item { count = r.Next(1, 1000), adminPrice = r.Next(500, 10000) * 10, pct = r.Next(3, 50), price = r.Next(500, 10000) * 10, canGiveBack = r.Next(10) < 7, measure = r.Next(10) < 5 ? "1 шт" : (r.Next(1, 10) * 100) + " шт", countToOrder = r.Next(1, 20) * 10, order = r.Next(10) < 3, name = names[r.Next(names.Count - 1)], groupId = groups[r.Next(groups.Count - 1)] } ); } return(result); }
public static object GetMsgLogActivityList() { ssmDataContext db = new ssmDataContext(); return(GetLogActivityList(db.logActivities.Where(gdf => gdf.informAdmin == false), db)); }
public static IList <item> GetEndItemList() { ssmDataContext db = new ssmDataContext(); return(db.items.Where(b => b.order.Value && b.count <= b.countToOrder).ToList()); }
public static void Refresh() { ssmDataContext db = new ssmDataContext(); cache = db.buyers.ToList(); }
public static logSale GetLogSalesById(int id) { ssmDataContext db = new ssmDataContext(); return(db.logSales.FirstOrDefault(b => b.id == id)); }
public static object GetSalesList() { ssmDataContext db = new ssmDataContext(); return(GetLogSalesList(db.logSales.Where(g => g.isGiveBack == false), db)); }