Esempio n. 1
0
        public bool PutProduct(ViewModels.ProductStokViewModel model)
        {
            var test = db.Urun.FirstOrDefault(m => m.urunID == model.urunID);

            if (test != null)
            {
                var marka = db.Marka.FirstOrDefault(x => x.marka1 == model.marka);
                if (marka != null)
                {
                    test.markaID = marka.markaID;
                }
                else
                {
                    var newmarka = new Models.Marka();
                    newmarka.marka1 = model.marka;
                    db.Marka.Add(newmarka);
                    db.SaveChanges();
                    test.markaID = newmarka.markaID;
                }

                test.ad            = model.ad;
                test.altKategoriID = model.altKategoriID;
                test.fiyat         = model.fiyat;
                test.imagePath     = "-";
                test.eklenmeTarihi = DateTime.Now;
                test.Stok.adet     = model.adet;
                if (model.adet <= 0)
                {
                    test.satinAlinmaDurumu = true;
                }

                db.SaveChanges();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public bool PostProduct(ViewModels.ProductStokViewModel model)
        {
            var stok = new Models.Stok();

            stok.adet = model.adet;
            db.Stok.Add(stok);
            db.SaveChanges();

            var Product = new Models.Urun();

            var marka = db.Marka.FirstOrDefault(x => x.marka1 == model.marka);

            if (marka != null)
            {
                Product.markaID = marka.markaID;
            }
            else
            {
                var yenimarka = new Models.Marka();
                yenimarka.marka1 = model.marka;
                db.Marka.Add(yenimarka);
                db.SaveChanges();
                Product.markaID = yenimarka.markaID;
            }

            Product.imagePath         = model.imagePath;
            Product.ad                = model.ad;
            Product.altKategoriID     = model.altKategoriID;
            Product.eklenmeTarihi     = DateTime.Now;
            Product.fiyat             = model.fiyat;
            Product.stokID            = stok.stokID;
            Product.satinAlinmaDurumu = false;

            db.Urun.Add(Product);
            db.SaveChanges();

            return(true);
        }