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 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 void Order(int id) { ssmDataContext db = new ssmDataContext(); item orderItem = db.items.FirstOrDefault(b => b.id == id); orderItem.order = true; db.SubmitChanges(); }
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 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(); }
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(); }