示例#1
0
        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);
        }
示例#2
0
        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();
        }
示例#3
0
        public static void Order(int id)
        {
            ssmDataContext db        = new ssmDataContext();
            item           orderItem = db.items.FirstOrDefault(b => b.id == id);

            orderItem.order = true;
            db.SubmitChanges();
        }
示例#4
0
        public static void Info(string message)
        {
            var db          = new ssmDataContext();
            var logActivity = new logActivity {
                action = message, informAdmin = false
            };

            db.logActivities.InsertOnSubmit(logActivity);
            db.SubmitChanges();
        }
示例#5
0
        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();
        }
示例#6
0
        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();
        }
示例#7
0
        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();
        }
示例#8
0
        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();
            }
        }
示例#9
0
        /// <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();
        }
示例#10
0
        /// <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();
        }
示例#11
0
        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();
                }
            }
        }
示例#12
0
        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();
        }