예제 #1
0
 public static void RemoveAssocPartByid(int index)
 {
     using (var con = new InventoryMgmtEntities())
     {
         productspart tempProductPart = con.productsparts.Find(index);
         con.productsparts.Remove(tempProductPart);
         con.SaveChanges();
     }
 }
예제 #2
0
        //Associated Parts

        public static void AddAssocPart(int product, int part)
        {
            using (var con = new InventoryMgmtEntities())
            {
                productspart temp = new productspart();
                temp.productid = product;
                temp.partid    = part;
                con.productsparts.Add(temp);
                con.SaveChanges();
            }
        }
예제 #3
0
        public static bool ModifyProductImproved(productsdb product, List <partsdb> partsList, List <productspart> originalParts)
        {
            using (var con = new InventoryMgmtEntities())
            {
                //Update Part Details
                productsdb productTemp = con.productsdbs.Find(product.productid);;
                productTemp.name  = product.name; productTemp.min = product.min; productTemp.max = product.max; productTemp.instock = product.instock;
                productTemp.price = product.price; productTemp.lastmodified = DateTime.Now;

                //Split list into associated parts that already exist and new parts
                List <partDerived> partDerivedList = new List <partDerived>();
                List <partsdb>     realParts       = new List <partsdb>();
                for (int i = 0; i < partsList.Count(); i++)
                {
                    if (partsList[i].GetType() == typeof(partDerived))
                    {
                        partDerived tempPart = (partDerived)(object)partsList[i];
                        partDerivedList.Add(tempPart);
                    }
                    else
                    {
                        realParts.Add(partsList[i]);
                    }
                }

                //Take original list and derived part list, where there is a match remove part from partListfinal
                List <productspart> partListFinal = originalParts;

                for (int i = 0; i < originalParts.Count(); i++)
                {
                    for (int j = 0; j < partDerivedList.Count(); j++)
                    {
                        if (originalParts[i].productpartid == partDerivedList[j].zproductpartid)
                        {
                            partListFinal.RemoveAll(u => u.productpartid == (int)partDerivedList[j].zproductpartid);
                        }
                    }
                    var temp = partListFinal;
                }

                //Remove all productparts from the db that are in the list partListFinal
                if (partListFinal.Count() > 0)
                {
                    for (int k = 0; k < partListFinal.Count(); k++)
                    {
                        productspart tempProductPart = con.productsparts.Find(partListFinal[k].productpartid);
                        con.productsparts.Remove(tempProductPart);
                    }
                }

                //Add new associated parts
                for (int l = 0; l < realParts.Count(); l++)
                {
                    productspart temp = new productspart();
                    temp.productid = product.productid;
                    temp.partid    = realParts[l].partid;
                    con.productsparts.Add(temp);
                }
                con.SaveChanges();
                return(true);
            }
        }