Esempio n. 1
0
        public void Delete(Int32 id)
        {
            var entity = _context.Materials.First(x => x.MaterialId == id);

            _context.Materials.Remove(entity);
            _context.SaveChanges();
        }
Esempio n. 2
0
        public ActionResult Create([Bind(Include = "MaterialId,Name,Cost")] Material material)
        {
            if (ModelState.IsValid)
            {
                db.Materials.Add(material);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(material));
        }
        public void UpdateProduct(Product product)
        {
            Product p = GetProduct(product.Id);

            p.Name          = product.Name;
            p.Category      = product.Category;
            p.PurchasePrice = product.PurchasePrice;
            p.RetailPrice   = product.RetailPrice;
            // context.Products.Update(product);
            context.SaveChanges();
        }
        public void Merge(Int32 materialIdToKeep, Int32 materialIdToDelete)
        {
            foreach (var entity in _context.ProductMaterials.Where(x => x.MaterialId == materialIdToDelete).ToList())
            {
                entity.MaterialId = materialIdToKeep;
            }
            _context.SaveChanges();
            var entity1 = _context.Materials.First(x => x.MaterialId == materialIdToDelete);

            _context.Materials.Remove(entity1);
            _context.SaveChanges();
        }
Esempio n. 5
0
        public Item UpdateItem(Item item)
        {
            var updateItem = GetPersistenceItemById(item.Id);

            if (updateItem != null)
            {
                updateItem.Name = item.Name;
                updateItem.Cost = item.Cost;
            }

            _dataContext.SaveChanges();

            return(Map(updateItem));
        }
Esempio n. 6
0
        public ActionResult Edit(FormCollection obj)
        {
            using (var db1 = new ProductDataContext())
            {
                //var myData = db1.ProductMaterials.Where(x => x.MaterialId == material.MaterialId).ToList();
                //myData.ForEach(m => m.MaterialId = int.Parse(obj["hidden1"]));
                //db.SaveChanges();
                Int32 deleteId = int.Parse(obj["hidden1"]);
                Int32 keepId   = int.Parse(obj["hidden2"]);

                var query = db1.ProductMaterials.Where(p => p.MaterialId == deleteId).ToList();
                foreach (var post in query)
                {
                    post.MaterialId = keepId;
                }
                db1.SaveChanges();

                var itemToRemove = db.Materials.SingleOrDefault(x => x.MaterialId == deleteId);

                if (itemToRemove != null)
                {
                    db.Materials.Remove(itemToRemove);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));

                //material.Name = obj["hidden1"].ToString();
                //db.Entry(material).State = EntityState.Modified;
                //db.SaveChanges();
                //return RedirectToAction("Index");
            }
        }
Esempio n. 7
0
        private void SaveProductImage(string file)
        {
            var splitedName = file.Split('.');

            var extension = splitedName[splitedName.Length - 1];

            var stream = File.OpenRead(file);

            byte[] buffer = new byte[stream.Length];

            stream.Read(buffer, 0, (int)stream.Length);

            using (ProductDataContext db = new ProductDataContext("StoreAppB"))
            {
                var product = db.Set <Product>().Find(int.Parse(ProductIDTxt.Text));

                ProductImage pi = new ProductImage
                {
                    ImageData      = buffer,
                    ImageMimeType  = extension,
                    SequenceNumber = short.Parse(SequenceNumber.Text),
                    Product        = product
                };

                db.Set <ProductImage>().Add(pi);
                db.SaveChanges();
            }
        }
 public void UpdateProductMaterials(ProductMaterial productMaterial)
 {
     _context.Entry(productMaterial).State = EntityState.Modified;
     _context.SaveChanges();
 }