コード例 #1
0
        public ActionResult Edit(SupplyDetail supplyDetail)
        {
            try
            {
                SupplyDetail _supplyDetail = Db.SupplyDetails.Find(supplyDetail.Id);


                if (supplyDetail.PurchasePrice > _supplyDetail.PurchasePrice)
                {
                    _supplyDetail.PurchasePrice = supplyDetail.PurchasePrice;
                }
                int quantity = supplyDetail.Quantity - _supplyDetail.Quantity;

                _supplyDetail.Quantity += quantity;

                Product product = Db.Products.Find(supplyDetail.ProductId);
                product.Quantity     += quantity;
                product.PurchasePrice = _supplyDetail.PurchasePrice;
                if (product.Quantity < 0)
                {
                    product.Quantity = 0;
                }

                Db.SaveChanges();

                return(RedirectToAction("Details", "Supply", new { id = supplyDetail.SupplyId }));
            }
            catch
            {
                ViewBag.ErrorMessage = "Error occured while updating supply details.";
                return(View("Error"));
            }
        }
コード例 #2
0
        public void SupplyDetail_ObjectCreation_Test(int foodItemCount, String requestDate, string sellerName, double packingCharge)
        {
            FoodDetail   fooditem     = p.CreateFoodDetail("Biriyani", 10, DateTime.Parse("2022/12/02"), 100.00);
            SupplyDetail supplyDetail = p.CreateSupplyDetail(foodItemCount, DateTime.Parse(requestDate), sellerName, packingCharge, fooditem);

            Assert.AreEqual(typeof(SupplyDetail), supplyDetail.GetType());
        }
コード例 #3
0
        public void SupplyDetail_FoodDetailObjectNull_Test(int foodItemCount, String requestDate, string sellerName, double packingCharge)
        {
            FoodDetail   fooditem = null;
            SupplyDetail sd       = p.CreateSupplyDetail(foodItemCount, DateTime.Parse(requestDate), sellerName, packingCharge, fooditem);

            Assert.AreEqual(fooditem, sd);
        }
コード例 #4
0
        public void TestForNull(int foodItemCount, string requestDate, string sellerName, double packingCharge)
        {
            DateTime     datetime   = DateTime.Parse(requestDate);
            FoodDetail   foodDetail = null;
            SupplyDetail supply     = program.CreateSupplyDetail(foodItemCount, datetime, sellerName, packingCharge, foodDetail);

            Assert.IsNull(supply);
        }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            SupplyDetail supplyDetail = db.SupplyDetails.Find(id);

            db.SupplyDetails.Remove(supplyDetail);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        //[TestCase(1, "2021/08/07", "abh", 20.00, 1)]
        public void CreateSupplyDetail_FoodItemObjectNull_ThrowsException(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge, int n)
        {
            Program    p = new Program();
            FoodDetail m;

            m = get(n);
            SupplyDetail res = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, m);

            Assert.That(res, Is.EqualTo(null));
        }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "SupplyId,SupplierName,ItemName,UnitPrice,NoOfUnits,TotalPrice,Date")] SupplyDetail supplyDetail)
 {
     if (ModelState.IsValid)
     {
         db.Entry(supplyDetail).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(supplyDetail));
 }
コード例 #8
0
        public void Put(int id, SupplyDetail supplyDetail)
        {
            var _supplyDetail = Db.SupplyDetails.Where(sp => sp.Id == id).FirstOrDefault();

            _supplyDetail.ProductId     = supplyDetail.ProductId;
            _supplyDetail.PurchasePrice = supplyDetail.PurchasePrice;
            _supplyDetail.Quantity      = supplyDetail.Quantity;
            _supplyDetail.SupplyId      = supplyDetail.SupplyId;
            Db.SaveChanges();
        }
コード例 #9
0
        public void CreateSupplyDetail_WhenCalled_ReturnSupplyDetailObject(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge)
        {
            SupplyDetail result = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, f);

            Assert.That(result.Count, Is.EqualTo(foodItemCount));
            Assert.That(result.RequestDate, Is.EqualTo(requestDate));
            Assert.That(result.SellerName, Is.EqualTo(sellerName));
            //Assert.That(result.PackingCharge, Is.EqualTo(packingCharge));
            Assert.That(result.FoodItem, Is.EqualTo(f));
        }
コード例 #10
0
        public ActionResult Create([Bind(Include = "SupplyId,SupplierName,ItemName,UnitPrice,NoOfUnits,TotalPrice,Date")] SupplyDetail supplyDetail)
        {
            if (ModelState.IsValid)
            {
                db.SupplyDetails.Add(supplyDetail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplyDetail));
        }
コード例 #11
0
ファイル: Class1.cs プロジェクト: kingKay28/Hands-on
        public void SupplyDetailCreateTest(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge)
        {
            SupplyDetail supply = progObj.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, this.food);

            Assert.That(supply.Count, Is.EqualTo(foodItemCount));
            Assert.That(supply.RequestDate, Is.EqualTo(requestDate));
            Assert.That(supply.SellerName, Is.EqualTo(sellerName));
            //double total = foodItemCount * food.Price + packingCharge;
            Assert.That(supply.TotalCost, Is.EqualTo(food.Price * foodItemCount + packingCharge));
            Assert.That(supply.FoodItem, Is.EqualTo(food));
        }
コード例 #12
0
        public void CreateSupllyDetail_WhenCreated_CreateAndReturnObject(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge, int n)
        {
            Program    p = new Program();
            FoodDetail m;

            m = get(n);
            SupplyDetail res = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, m);

            Assert.That(res.Count, Is.EqualTo(foodItemCount));
            Assert.That(res.RequestDate, Is.EqualTo(requestDate));
            Assert.That(res.SellerName, Is.EqualTo(sellerName));
            Assert.That(res.FoodItem, Is.EqualTo(m));
        }
コード例 #13
0
        // GET: SupplyDetails/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            SupplyDetail supplyDetail = db.SupplyDetails.Find(id);

            if (supplyDetail == null)
            {
                return(HttpNotFound());
            }
            return(View(supplyDetail));
        }
コード例 #14
0
        public void CreateSupplyDetail_WhenCreated_ReturnObject(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge)
        {
            SupplyDetail c = null;

            try
            {
                c = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, food);
                Assert.IsNotNull(c);
            }
            catch
            {
                Assert.Fail("Supply details Object not created successfully");
            }
        }
コード例 #15
0
            public void CheckSupplyDetailObjectCreation(int Count, DateTime Requested_Date, string Seller_Name, double Package_Charge)
            {
                SupplyDetail SD = null;

                try
                {
                    SD = p.CreateSupplyDetail(Count, Requested_Date, Seller_Name, Package_Charge, Food);
                    Assert.IsNotNull(SD);
                }
                catch
                {
                    Assert.Fail("SupplyDetail Object not created successfully");
                }
            }
コード例 #16
0
        public string TestSupplyDetails(int foodItemCount, string requestdate, string sellerName, double packingCharge)
        {
            DateTime datetime   = DateTime.Parse(requestdate);
            var      foodDetail = new FoodDetail()
            {
                Name       = "Mathew",
                DishType   = (FoodDetail.Category) 1,
                ExpiryDate = DateTime.Parse("2020-03-30"),
                Price      = 30
            };
            SupplyDetail supplyDetail = program.CreateSupplyDetail(foodItemCount, datetime, sellerName, packingCharge, foodDetail);
            String       result       = string.Format("{0},{1},{2},{3}", supplyDetail.SellerName, supplyDetail.RequestDate.ToShortDateString(), supplyDetail.Count, supplyDetail.TotalCost);


            return(result);
        }
コード例 #17
0
        public ActionResult Delete(int id)
        {
            SupplyDetail supplyDetail = Db.SupplyDetails.Find(id);
            int          SupplyId     = supplyDetail.Supply.Id;
            var          ProductInDb  = Db.Products.Find(supplyDetail.ProductId);

            ProductInDb.Quantity -= supplyDetail.Quantity;

            if (ProductInDb.Quantity < 0)
            {
                ProductInDb.Quantity = 0;
            }
            Db.SupplyDetails.Remove(supplyDetail);
            Db.SaveChanges();

            return(RedirectToAction("Details", "Supply", new { id = SupplyId }));
        }
コード例 #18
0
        public ActionResult Create(SupplyViewModel vm)
        {
            try
            {
                var UserId = User.Identity.GetUserId();

                Supply supply = new Supply();
                supply.UserId     = UserId;
                supply.SupplierId = vm.SupplierId;
                supply.SupplyDate = DateTime.Today;

                Db.Supplies.Add(supply);
                Db.SaveChanges();

                int SupplyId = supply.Id;

                foreach (var item in vm.Details)
                {
                    SupplyDetail detail = new SupplyDetail();
                    detail.ProductId     = item.ProductId;
                    detail.PurchasePrice = item.Price;
                    detail.Quantity      = item.Quantity;
                    detail.SupplyId      = SupplyId;

                    var ProductInDb = Db.Products.Find(detail.ProductId);

                    ProductInDb.Quantity += detail.Quantity;

                    Db.SupplyDetails.Add(detail);
                }

                Db.SaveChanges();
                return(RedirectToAction("Details", new { id = SupplyId }));
            }
            catch
            {
                ViewBag.ErrorMessage = "Error occured while adding supply";
                return(View("Error"));
            }
        }
コード例 #19
0
        public ActionResult Edit(int id)
        {
            SupplyDetail supplyDetail = Db.SupplyDetails.Find(id);

            return(View(supplyDetail));
        }
コード例 #20
0
 public ActionResult Edit(int id, SupplyDetail supplyDetail)
 {
     return(View());
 }
コード例 #21
0
            public void Testing_SupplyDetail_NotNull(int count, DateTime requestedDate, string SellerName, double packageCharge, FoodDetail food)
            {
                SupplyDetail s = p.CreateSupplyDetail(count, requestedDate, SellerName, packageCharge, food);

                Assert.IsNull(s);
            }
コード例 #22
0
        public void CreateSupplyDetail_ItemObjectNull_ThrowsException(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge, FoodDetail food)
        {
            SupplyDetail result = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, food);

            Assert.IsNull(result);
        }
コード例 #23
0
ファイル: Class1.cs プロジェクト: kingKay28/Hands-on
        public void SupplyNullFoodTest(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge, FoodDetail food)
        {
            SupplyDetail supply = progObj.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, food);

            Assert.That(supply, Is.EqualTo(null));
        }
コード例 #24
0
        public static void GetSupplyOrder(String[] PID, String[] SuppID, int[] QNTY, String[] SuppID2, int[] QNTY2, String[] SuppID3, int[] QNTY3)
        {
            int i = 0; int j = 0;

            PurchaseOrder pomain             = new PurchaseOrder();
            PurchaseOrder pomain2            = new PurchaseOrder();
            PurchaseOrder pomain3            = new PurchaseOrder();

            List <PurchaseOrderDetail> lpod  = new List <PurchaseOrderDetail>();
            List <PurchaseOrderDetail> lpod2 = new List <PurchaseOrderDetail>();
            List <PurchaseOrderDetail> lpod3 = new List <PurchaseOrderDetail>();



            foreach (String p in PID)
            {
                var q = from x in context.Products
                        where x.ItemNumber == p
                        select x;
                PurchaseOrder po = new PurchaseOrder();
                if (SuppID[i].Equals(q.First <Product>().Supplier1ID) || SuppID[i].Equals(q.First <Product>().Supplier2ID) || SuppID[i].Equals(q.First <Product>().Supplier3ID))
                {
                    if (SuppID[i].Equals(q.First <Product>().Supplier1ID))
                    {
                        po.SupplierCode = q.First <Product>().Supplier1ID;
                        po.DateCreated  = DateTime.Now;
                        po.Status       = "Pending";
                        pomain          = po;
                    }
                    else if (SuppID[i].Equals(q.First <Product>().Supplier2ID))
                    {
                        po.SupplierCode = q.First <Product>().Supplier2ID;
                        po.DateCreated  = DateTime.Now;
                        po.Status       = "Pending";
                        pomain2         = po;
                    }
                    else if (SuppID[i].Equals(q.First <Product>().Supplier3ID))
                    {
                        po.SupplierCode = q.First <Product>().Supplier3ID;
                        po.DateCreated  = DateTime.Now;
                        po.Status       = "Pending";
                        pomain3         = po;
                    }



                    if (SuppID[i].Equals(q.First <Product>().Supplier1ID))
                    {
                        PurchaseOrderDetail pod = new PurchaseOrderDetail();

                        var q1 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod.ItemNumber  = p;
                        pod.Description = q.First <Product>().Description;
                        pod.Quantity    = QNTY[i];
                        String g = q1.First <Product>().Supplier1ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;
                        SupplyDetail s = z.First <SupplyDetail>();

                        pod.Price = s.Price;
                        lpod.Add(pod);
                    }
                    else if (SuppID[i].Equals(q.First <Product>().Supplier2ID))
                    {
                        PurchaseOrderDetail pod = new PurchaseOrderDetail();

                        var q1 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod.ItemNumber  = p;
                        pod.Description = q.First <Product>().Description;
                        pod.Quantity    = QNTY[i];
                        String g = q1.First <Product>().Supplier2ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod.Price = z.First <SupplyDetail>().Price;
                        lpod2.Add(pod);
                    }
                    else if (SuppID[i].Equals(q.First <Product>().Supplier3ID))
                    {
                        PurchaseOrderDetail pod = new PurchaseOrderDetail();

                        var q1 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod.ItemNumber  = p;
                        pod.Description = q1.First <Product>().Description;
                        pod.Quantity    = QNTY[i];
                        String g = q1.First <Product>().Supplier3ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod.Price = z.First <SupplyDetail>().Price;
                        lpod3.Add(pod);
                    }
                }
                i++;
            }



            foreach (String p in PID)
            {
                PurchaseOrder po2 = new PurchaseOrder();
                var           q   = from x in context.Products
                                    where x.ItemNumber == p
                                    select x;
                if (SuppID2[j].Equals(q.First <Product>().Supplier1ID) || SuppID2[j].Equals(q.First <Product>().Supplier2ID) || SuppID2[j].Equals(q.First <Product>().Supplier3ID))
                {
                    String t = q.First <Product>().Supplier1ID;
                    if (SuppID2[j].Equals(q.First <Product>().Supplier1ID))
                    {
                        po2.SupplierCode = q.First <Product>().Supplier1ID;
                        po2.DateCreated  = DateTime.Now;
                        po2.Status       = "Pending";
                        pomain           = po2;
                    }
                    else if (SuppID2[j].Equals(q.First <Product>().Supplier2ID))
                    {
                        po2.SupplierCode = q.First <Product>().Supplier2ID;
                        po2.DateCreated  = DateTime.Now;
                        po2.Status       = "Pending";
                        pomain2          = po2;
                    }
                    else if (SuppID2[j].Equals(q.First <Product>().Supplier3ID))
                    {
                        po2.SupplierCode = q.First <Product>().Supplier3ID;
                        po2.DateCreated  = DateTime.Now;
                        po2.Status       = "Pending";
                        pomain3          = po2;
                    }



                    if (SuppID2[j].Equals(q.First <Product>().Supplier1ID) && QNTY2[j] > 0)
                    {
                        PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
                        var q2 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod2.ItemNumber  = p;
                        pod2.Description = q2.First <Product>().Description;
                        pod2.Quantity    = QNTY2[j];
                        String g = q2.First <Product>().Supplier1ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod2.Price = z.First <SupplyDetail>().Price;
                        lpod.Add(pod2);
                    }
                    else if (SuppID2[j].Equals(q.First <Product>().Supplier2ID) && QNTY2[j] > 0)
                    {
                        PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
                        var q2 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod2.ItemNumber  = p;
                        pod2.Description = q2.First <Product>().Description;
                        pod2.Quantity    = QNTY2[j];
                        String g = q2.First <Product>().Supplier2ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod2.Price = z.First <SupplyDetail>().Price;
                        lpod2.Add(pod2);
                    }
                    else if (SuppID2[j].Equals(q.First <Product>().Supplier3ID) && QNTY2[j] > 0)
                    {
                        PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
                        var q2 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod2.ItemNumber  = p;
                        pod2.Description = q2.First <Product>().Description;
                        pod2.Quantity    = QNTY2[j];
                        String g = q2.First <Product>().Supplier3ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod2.Price = z.First <SupplyDetail>().Price;
                        lpod3.Add(pod2);
                    }
                }
                j++;
            }

            int k = 0;


            foreach (String p in PID)
            {
                PurchaseOrder po3 = new PurchaseOrder();
                var           q   = from x in context.Products
                                    where x.ItemNumber == p
                                    select x;

                if (SuppID3[k].Equals(q.First <Product>().Supplier1ID) || SuppID3[k].Equals(q.First <Product>().Supplier2ID) || SuppID3[k].Equals(q.First <Product>().Supplier3ID))
                {
                    if (SuppID3[k].Equals(q.First <Product>().Supplier1ID))
                    {
                        po3.SupplierCode = q.First <Product>().Supplier1ID;
                        po3.DateCreated  = DateTime.Now;
                        po3.Status       = "Pending";
                        pomain           = po3;
                    }
                    else if (SuppID3[k].Equals(q.First <Product>().Supplier2ID))
                    {
                        po3.SupplierCode = q.First <Product>().Supplier2ID;
                        po3.DateCreated  = DateTime.Now;
                        po3.Status       = "Pending";
                        pomain2          = po3;
                    }
                    else if (SuppID3[k].Equals(q.First <Product>().Supplier3ID))
                    {
                        po3.SupplierCode = q.First <Product>().Supplier3ID;
                        po3.DateCreated  = DateTime.Now;
                        po3.Status       = "Pending";
                        pomain3          = po3;
                    }



                    if (SuppID3[k].Equals(q.First <Product>().Supplier1ID) && QNTY3[k] > 0)
                    {
                        PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
                        var q3 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod3.ItemNumber  = p;
                        pod3.Description = q3.First <Product>().Description;
                        pod3.Quantity    = QNTY3[k];
                        String g = q3.First <Product>().Supplier1ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod3.Price = z.First <SupplyDetail>().Price;
                        lpod.Add(pod3);
                    }
                    else if (SuppID3[k].Equals(q.First <Product>().Supplier2ID) && QNTY3[k] > 0)
                    {
                        PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
                        var q3 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod3.ItemNumber  = p;
                        pod3.Description = q3.First <Product>().Description;
                        pod3.Quantity    = QNTY3[k];
                        String g = q3.First <Product>().Supplier2ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod3.Price = z.First <SupplyDetail>().Price;
                        lpod2.Add(pod3);
                    }
                    else if (SuppID3[k].Equals(q.First <Product>().Supplier3ID) && QNTY3[k] > 0)
                    {
                        PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
                        var q3 = from x in context.Products
                                 where x.ItemNumber == p
                                 select x;
                        pod3.ItemNumber  = p;
                        pod3.Description = q3.First <Product>().Description;
                        pod3.Quantity    = QNTY3[k];
                        String g = q3.First <Product>().Supplier3ID;
                        var    z = from x in context.SupplyDetails
                                   where x.SupplierCode == g && x.ItemNumber == p
                                   select x;

                        pod3.Price = z.First <SupplyDetail>().Price;
                        lpod3.Add(pod3);
                    }
                }
                k++;
            }
            if (pomain.SupplierCode != null)
            {
                PurchaseOrderDAO.CreatePurchaseOrder(pomain, lpod);
            }
            if (pomain2.SupplierCode != null)
            {
                PurchaseOrderDAO.CreatePurchaseOrder(pomain2, lpod2);
            }
            if (pomain3.SupplierCode != null)
            {
                PurchaseOrderDAO.CreatePurchaseOrder(pomain3, lpod3);
            }
        }
コード例 #25
0
        //Check if null value provided for food item object, then Null supply detail should be obtained



        public void CheckForNullSupplyObject(int foodItemCount, DateTime requestDate, string sellerName, double packingCharge, FoodDetail food)
        {
            SupplyDetail supply = p.CreateSupplyDetail(foodItemCount, requestDate, sellerName, packingCharge, food);

            Assert.IsNull(supply);
        }
コード例 #26
0
        //public static void GetSupplyOrder(String[] PID, String[] SuppID, int[] QNTY, String[] SuppID2, int[] QNTY2, String[] SuppID3, int[] QNTY3)
        //{
        //UniversityStoreEntities context = new UniversityStoreEntities();
        //int i = 0; int j = 0;

        //PurchaseOrder pomain = new PurchaseOrder();
        //PurchaseOrder pomain2 = new PurchaseOrder();
        //PurchaseOrder pomain3 = new PurchaseOrder();

        //List<PurchaseOrderDetail> lpod = new List<PurchaseOrderDetail>();
        //List<PurchaseOrderDetail> lpod2 = new List<PurchaseOrderDetail>();
        //List<PurchaseOrderDetail> lpod3 = new List<PurchaseOrderDetail>();



        //foreach (String p in PID)
        //{
        //    var q = from x in context.Products
        //            where x.ItemNumber == p
        //            select x;

        //    PurchaseOrder po = new PurchaseOrder();
        //    if (SuppID[i].Equals(q.First<Product>().Supplier1ID) || SuppID[i].Equals(q.First<Product>().Supplier2ID) || SuppID[i].Equals(q.First<Product>().Supplier3ID))
        //    {
        //        if (SuppID[i].Equals(q.First<Product>().Supplier1ID))
        //        {
        //            po.SupplierCode = q.First<Product>().Supplier1ID;
        //            po.DateCreated = DateTime.Now;
        //            po.Status = "Pending";
        //            pomain = po;



        //        }
        //        else if (SuppID[i].Equals(q.First<Product>().Supplier2ID))
        //        {
        //            po.SupplierCode = q.First<Product>().Supplier2ID;
        //            po.DateCreated = DateTime.Now;
        //            po.Status = "Pending";
        //                pomain2 = po;

        //        }
        //        else if (SuppID[i].Equals(q.First<Product>().Supplier3ID))
        //        {
        //            po.SupplierCode = q.First<Product>().Supplier3ID;
        //            po.DateCreated = DateTime.Now;
        //            po.Status = "Pending";

        //                pomain3 = po;

        //        }



        //        if (SuppID[i].Equals(q.First<Product>().Supplier1ID))
        //        {
        //            PurchaseOrderDetail pod = new PurchaseOrderDetail();

        //            var q1 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod.ItemNumber = p;
        //            pod.Description = q.First<Product>().Description;
        //            pod.Quantity = QNTY[i];
        //            String g = q1.First<Product>().Supplier1ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;
        //            SupplyDetail s = z.First<SupplyDetail>();

        //            pod.Price = s.Price;

        //            lpod.Add(pod);

        //        }
        //        else if (SuppID[i].Equals(q.First<Product>().Supplier2ID))
        //        {
        //            PurchaseOrderDetail pod = new PurchaseOrderDetail();

        //            var q1 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod.ItemNumber = p;
        //            pod.Description = q.First<Product>().Description;
        //            pod.Quantity = QNTY[i];
        //            String g = q1.First<Product>().Supplier2ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod.Price = z.First<SupplyDetail>().Price;

        //            lpod2.Add(pod);

        //        }
        //        else if (SuppID[i].Equals(q.First<Product>().Supplier3ID))
        //        {
        //            PurchaseOrderDetail pod = new PurchaseOrderDetail();

        //            var q1 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod.ItemNumber = p;
        //            pod.Description = q1.First<Product>().Description;
        //            pod.Quantity = QNTY[i];
        //            String g = q1.First<Product>().Supplier3ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod.Price = z.First<SupplyDetail>().Price;

        //            lpod3.Add(pod);

        //        }


        //    }
        //    i++;

        //}



        //foreach (String p in PID)
        //{

        //    PurchaseOrder po2 = new PurchaseOrder();
        //    var q = from x in context.Products
        //            where x.ItemNumber == p
        //            select x;

        //    if (SuppID2[j].Equals(q.First<Product>().Supplier1ID) || SuppID2[j].Equals(q.First<Product>().Supplier2ID) || SuppID2[j].Equals(q.First<Product>().Supplier3ID))
        //    {
        //        String t = q.First<Product>().Supplier1ID;
        //        if (SuppID2[j].Equals(q.First<Product>().Supplier1ID))
        //        {

        //            po2.SupplierCode = q.First<Product>().Supplier1ID;
        //            po2.DateCreated = DateTime.Now;
        //            po2.Status = "Pending";



        //                pomain = po2;



        //        }
        //        else if (SuppID2[j].Equals(q.First<Product>().Supplier2ID))
        //        {
        //            po2.SupplierCode = q.First<Product>().Supplier2ID;
        //            po2.DateCreated = DateTime.Now;
        //            po2.Status = "Pending";
        //            pomain2 = po2;



        //        }
        //        else if (SuppID2[j].Equals(q.First<Product>().Supplier3ID))
        //        {
        //            po2.SupplierCode = q.First<Product>().Supplier3ID;
        //            po2.DateCreated = DateTime.Now;
        //            po2.Status = "Pending";
        //            pomain3 = po2;

        //                pomain3 = po2;

        //        }



        //        if (SuppID2[j].Equals(q.First<Product>().Supplier1ID) && QNTY2[j] > 0)
        //        {
        //            PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
        //            var q2 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod2.ItemNumber = p;
        //            pod2.Description = q2.First<Product>().Description;
        //            pod2.Quantity = QNTY2[j];
        //            String g = q2.First<Product>().Supplier1ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod2.Price = z.First<SupplyDetail>().Price;

        //           lpod.Add(pod2);

        //        }
        //        else if (SuppID2[j].Equals(q.First<Product>().Supplier2ID) && QNTY2[j] > 0)
        //        {
        //            PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
        //            var q2 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod2.ItemNumber = p;
        //            pod2.Description = q2.First<Product>().Description;
        //            pod2.Quantity = QNTY2[j];
        //            String g = q2.First<Product>().Supplier2ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod2.Price = z.First<SupplyDetail>().Price;

        //            lpod2.Add(pod2);

        //        }
        //        else if (SuppID2[j].Equals(q.First<Product>().Supplier3ID) && QNTY2[j] > 0)
        //        {
        //            PurchaseOrderDetail pod2 = new PurchaseOrderDetail();
        //            var q2 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod2.ItemNumber = p;
        //            pod2.Description = q2.First<Product>().Description;
        //            pod2.Quantity = QNTY2[j];
        //            String g = q2.First<Product>().Supplier3ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod2.Price = z.First<SupplyDetail>().Price;

        //            lpod3.Add(pod2);

        //        }

        //    }
        //    j++;

        //}

        //int k = 0;


        //foreach (String p in PID)
        //{
        //    PurchaseOrder po3 = new PurchaseOrder();
        //    var q = from x in context.Products
        //            where x.ItemNumber == p
        //            select x;


        //    if (SuppID3[k].Equals(q.First<Product>().Supplier1ID) || SuppID3[k].Equals(q.First<Product>().Supplier2ID) || SuppID3[k].Equals(q.First<Product>().Supplier3ID))
        //    {
        //        if (SuppID3[k].Equals(q.First<Product>().Supplier1ID))
        //        {
        //            po3.SupplierCode = q.First<Product>().Supplier1ID;
        //            po3.DateCreated = DateTime.Now;
        //            po3.Status = "Pending";
        //            pomain = po3;



        //        }
        //        else if (SuppID3[k].Equals(q.First<Product>().Supplier2ID))
        //        {
        //            po3.SupplierCode = q.First<Product>().Supplier2ID;
        //            po3.DateCreated = DateTime.Now;
        //            po3.Status = "Pending";
        //            pomain2 = po3;

        //        }
        //        else if (SuppID3[k].Equals(q.First<Product>().Supplier3ID))
        //        {
        //            po3.SupplierCode = q.First<Product>().Supplier3ID;
        //            po3.DateCreated = DateTime.Now;
        //            po3.Status = "Pending";
        //            pomain3 = po3;

        //        }



        //        if (SuppID3[k].Equals(q.First<Product>().Supplier1ID) && QNTY3[k] > 0)
        //        {
        //            PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
        //            var q3 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod3.ItemNumber = p;
        //            pod3.Description = q3.First<Product>().Description;
        //            pod3.Quantity = QNTY3[k];
        //            String g = q3.First<Product>().Supplier1ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod3.Price = z.First<SupplyDetail>().Price;

        //            lpod.Add(pod3);

        //        }
        //        else if (SuppID3[k].Equals(q.First<Product>().Supplier2ID) && QNTY3[k] > 0)
        //        {
        //            PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
        //            var q3 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod3.ItemNumber = p;
        //            pod3.Description = q3.First<Product>().Description;
        //            pod3.Quantity = QNTY3[k];
        //            String g = q3.First<Product>().Supplier2ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod3.Price = z.First<SupplyDetail>().Price;
        //            lpod2.Add(pod3);


        //        }
        //        else if (SuppID3[k].Equals(q.First<Product>().Supplier3ID) && QNTY3[k] > 0)
        //        {
        //            PurchaseOrderDetail pod3 = new PurchaseOrderDetail();
        //            var q3 = from x in context.Products
        //                     where x.ItemNumber == p
        //                     select x;
        //            pod3.ItemNumber = p;
        //            pod3.Description = q3.First<Product>().Description;
        //            pod3.Quantity = QNTY3[k];
        //            String g = q3.First<Product>().Supplier3ID;
        //            var z = from x in context.SupplyDetails
        //                    where x.SupplierCode == g && x.ItemNumber == p
        //                    select x;

        //            pod3.Price = z.First<SupplyDetail>().Price;

        //            lpod3.Add(pod3);

        //        }
        //    }
        //    k++;

        //}
        //if (pomain.SupplierCode != null&& lpod.Count>0)
        //    PurchaseOrderDAO.CreatePurchaseOrder(pomain, lpod);
        //if (pomain2.SupplierCode != null&&lpod2.Count>0)
        //    PurchaseOrderDAO.CreatePurchaseOrder(pomain2, lpod2);
        //if (pomain3.SupplierCode != null&&lpod3.Count>0)
        //    PurchaseOrderDAO.CreatePurchaseOrder(pomain3, lpod3);

        public static void GetSupplyOrder(String[] PID, String[] SuppID, int[] QNTY, String[] SuppID2, int[] QNTY2, String[] SuppID3, int[] QNTY3)
        {
            List <PurchaseOrder> po = new List <PurchaseOrder>();
            List <string>        currentSuppylists = new List <string>();
            List <Int32>         supplierPOid      = new List <Int32>();
            //PurchaseOrder pon = new PurchaseOrder();
            List <PurchaseOrderDetail> pod = new List <PurchaseOrderDetail>();
            UniversityStoreEntities    context = new UniversityStoreEntities();
            int i = 0; int j = 0;

            foreach (String s in PID)
            {
                var q = from x in context.Products
                        where x.ItemNumber == s
                        select x;
                Product product     = q.First <Product>();
                string  description = product.Description;
                if (SuppID[i].Equals(q.First <Product>().Supplier1ID) || SuppID[i].Equals(q.First <Product>().Supplier2ID) || SuppID[i].Equals(q.First <Product>().Supplier3ID))
                {
                    if (SuppID[i].Equals(q.First <Product>().Supplier1ID))
                    {
                        string supplir = SuppID[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier1ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            supplierPOid.Add(pid);
                            currentSuppylists.Add(supID);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY[i], description);
                        }
                    }
                    if (SuppID[i].Equals(q.First <Product>().Supplier2ID))
                    {
                        string supplir = SuppID[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier2ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            supplierPOid.Add(pid);
                            currentSuppylists.Add(supID);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY[i], description);
                        }
                    }
                    if (SuppID[i].Equals(q.First <Product>().Supplier3ID))
                    {
                        string supplir = SuppID[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier3ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY2[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            supplierPOid.Add(pid);
                            currentSuppylists.Add(supID);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY[i], description);
                        }
                    }
                }
                if (SuppID2[i].Equals(q.First <Product>().Supplier1ID) || SuppID2[i].Equals(q.First <Product>().Supplier2ID) || SuppID2[i].Equals(q.First <Product>().Supplier3ID))
                {
                    if (SuppID2[i].Equals(q.First <Product>().Supplier1ID))
                    {
                        string supplir = SuppID2[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier1ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY2[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            supplierPOid.Add(pid);
                            currentSuppylists.Add(supID);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY2[i], description);
                        }
                    }
                    if (SuppID2[i].Equals(q.First <Product>().Supplier2ID))
                    {
                        string supplir = SuppID2[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier2ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY2[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            supplierPOid.Add(pid);
                            currentSuppylists.Add(supID);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY2[i], description);
                        }
                    }
                    if (SuppID2[i].Equals(q.First <Product>().Supplier3ID))
                    {
                        string supplir = SuppID2[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier3ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY2[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            currentSuppylists.Add(supID);
                            supplierPOid.Add(pid);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY2[i], description);
                        }
                    }
                }
                if (SuppID3[i].Equals(q.First <Product>().Supplier1ID) || SuppID3[i].Equals(q.First <Product>().Supplier2ID) || SuppID3[i].Equals(q.First <Product>().Supplier3ID))
                {
                    if (SuppID3[i].Equals(q.First <Product>().Supplier1ID))
                    {
                        string supplir = SuppID3[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier1ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY3[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            currentSuppylists.Add(supID);
                            supplierPOid.Add(pid);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY3[i], description);
                        }
                    }
                    if (SuppID3[i].Equals(q.First <Product>().Supplier2ID))
                    {
                        string supplir = SuppID3[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier2ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY3[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            currentSuppylists.Add(supID);
                            supplierPOid.Add(pid);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY3[i], description);
                        }
                    }
                    if (SuppID3[i].Equals(q.First <Product>().Supplier3ID))
                    {
                        string supplir = SuppID[i];
                        var    kk      = from x in context.SupplyDetails
                                         where x.SupplierCode == supplir && x.ItemNumber == s
                                         select x;
                        SupplyDetail ssd     = kk.First <SupplyDetail>();
                        string       priceee = ssd.Price.ToString();
                        string       supID   = q.First <Product>().Supplier3ID;
                        if (currentSuppylists.Contains(supID))
                        {
                            int pos  = currentSuppylists.IndexOf(supID);
                            int ppid = supplierPOid[pos];
                            PurchaseOrderDAO.generateDetails(ppid, priceee, s, QNTY3[i], description);
                        }
                        else
                        {
                            int pid = PurchaseOrderDAO.generatePO(supID);
                            currentSuppylists.Add(supID);
                            supplierPOid.Add(pid);
                            PurchaseOrderDAO.generateDetails(pid, priceee, s, QNTY3[i], description);
                        }
                    }
                }
                i++;
            }


            //if (pomain.SupplierCode != null)
            //    PurchaseOrderDAO.CreatePurchaseOrder(pomain, lpod);
            //if (pomain2.SupplierCode != null)
            //    PurchaseOrderDAO.CreatePurchaseOrder(pomain2, lpod2);
            //if (pomain3.SupplierCode != null)
            //    PurchaseOrderDAO.CreatePurchaseOrder(pomain3, lpod3);
        }
コード例 #27
0
        public void CreateSupplyDetail_WhenCalled_ReturnSupplyDetail(int foodItemCount, string requestDate, string sellerName, double packingCharge)
        {
            SupplyDetail s = p.CreateSupplyDetail(foodItemCount, DateTime.Parse(requestDate), sellerName, packingCharge, fd);

            Assert.That(s, Is.TypeOf <SupplyDetail>());
        }