Ejemplo n.º 1
0
        public bool UpdateQuantityHampers(int hID, int count)
        {
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    var item = ent.hampers.Where(x => x.hamperid == hID).FirstOrDefault();
                    var prd  = ent.product.Where(x => x.pid == item.productid).FirstOrDefault();

                    int hmpQuantity = Convert.ToInt32(item.quantity);

                    if (hmpQuantity != count)
                    {
                        if (item.quantity < count)
                        {
                            if (prd.stoch >= (count - hmpQuantity))
                            {
                                prd.stoch    -= count - hmpQuantity;
                                item.quantity = count;
                                ent.SaveChanges();
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else if (hmpQuantity > count)
                        {
                            prd.stoch    += hmpQuantity - count;
                            item.quantity = count;
                            ent.SaveChanges();
                        }
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 2
0
        public bool InsertOrderDetail(orderdetail obj)
        {//YENİ SİPARİŞLERİN DETAYLI HALİNİN EKLENMESİ
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    orderid = ent.order.Where(x => x.userid == obj.userid).Max(x => x.orderid);
                    int uID = Convert.ToInt32(obj.userid);

                    var hmpcopy = GetHampers(uID).ToList();
                    foreach (HamperContract hmpc in hmpcopy)
                    {
                        obj.orderid  = orderid;
                        obj.userid   = hmpc.userid;
                        obj.pid      = hmpc.pid;
                        obj.price    = hmpc.tprice;
                        obj.quantity = hmpc.quantity;
                        ent.orderdetail.Add(obj);
                        ent.SaveChanges();

                        WriteDebugLogInfo(DateTime.Now.ToString() + "  userid = " + uID.ToString() + " , pid =" + hmpc.pid.ToString() + "  üründen  " + hmpc.quantity + "  adet sipariş etti");
                    }


                    List <hampers> hmp = ent.hampers.Where(x => x.userid == obj.userid && x.status == 1).ToList();
                    if (hmp != null)
                    {
                        foreach (hampers hmpcpy in hmp)
                        {
                            hmpcpy.status = 3;
                            ent.SaveChanges();
                        }
                    }
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 3
0
        public bool UpdateHampers(hampers obj)
        {//SEPETTEKİ ÜRÜNÜN ADEDİ İLE TARİHİNİN GÜNCELLENMESİ ------ ÜRÜN YOK İSE EKLEMESİ.
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    var prd = ent.product.Where(x => x.pid == obj.productid).FirstOrDefault();

                    if (prd.stoch >= obj.quantity)                                                                                                  // Seçilen ürün adedinin stoklarımızda mevcut olup olmadığını kontrol ediyor
                    {
                        var hmp = ent.hampers.Where(x => x.userid == obj.userid && x.productid == obj.productid && x.status == 1).FirstOrDefault(); // bu üründen sepetimizde olup olmadığına bakıyor.

                        if (hmp != null)                                                                                                            // ürün sepetimizde var ise adet ve tarihini güncelliyor.
                        {
                            hmp.quantity        += obj.quantity;
                            hmp.date             = DateTime.Now;
                            ent.Entry(hmp).State = EntityState.Modified;
                            ent.SaveChanges();
                        }
                        else // yok ise ürünü oluşturuyor.
                        {
                            obj.status = 1;
                            ent.hampers.Add(obj);
                            ent.SaveChanges();
                        }
                        prd.stoch -= obj.quantity; // seçilen ürün kadar stoktan düşüyor.
                        ent.SaveChanges();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 4
0
 public bool DeleteUsers(int uID)
 {
     try
     {
         using (StajEntities ent = new StajEntities())
         {
             var item = ent.users.Where(x => x.userid == uID).FirstOrDefault();
             ent.Entry(item).State = EntityState.Deleted;
             ent.SaveChanges();
         }
         return(true);
     }
     catch (Exception)
     {
         throw;
     }
 }
Ejemplo n.º 5
0
        public bool InsertProduct(product obj)
        {//ADMİN PANELİ ÜRÜN EKLEME
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    ent.product.Add(obj);
                    ent.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 6
0
        public bool InsertUsers(users obj)
        {
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    ent.users.Add(obj);
                    ent.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 7
0
        public bool DeleteProduct(int pID)
        {//ADMİN PANELİ ÜRÜN SİLME
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    var item = ent.product.Where(x => x.pid == pID).FirstOrDefault();
                    ent.Entry(item).State = EntityState.Deleted;
                    ent.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 8
0
        public bool InsertOrder(order obj)
        {//YENİ SİPARİŞ OLUŞTURULMASI - SİPARİŞ LİSTESİNE YENİ ÜRÜN EKLENMESİ
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    List <hampers> hmp = ent.hampers.Where(x => x.userid == obj.userid && x.status == 1).ToList();

                    obj.item = hmp.Count();
                    ent.order.Add(obj);
                    ent.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }
Ejemplo n.º 9
0
        public bool DeleteHampers(int hID, int uID)
        {//SEPETTEKİ ÜRÜNÜN KALDIRILMASI
            try
            {
                using (StajEntities ent = new StajEntities())
                {
                    var item = ent.hampers.Where(x => x.hamperid == hID && x.userid == uID).FirstOrDefault();
                    var prd  = ent.product.Where(x => x.pid == item.productid).FirstOrDefault();
                    prd.stoch  += item.quantity;
                    item.date   = DateTime.Now;
                    item.status = 2;
                    ent.SaveChanges();
                }
                return(true);
            }
            catch (Exception)
            {
                return(false);

                throw;
            }
        }