//每确认一次carton收取情况,同步一次该po的ctn收货总量、库存数量及pcs收货总量、库存数量
        public void SyncPurchaseOrder(CartonDetail cartonDetailSample)
        {
            var pl    = cartonDetailSample.PurchaseOrderSummary;
            var po    = pl.PurchaseOrder;
            var preId = pl.PreReceiveOrder.Id;

            //查询preId为当前packinglist且po为当前po的cartondetail对象
            //同步ctn收货总量、库存数量
            pl.ActualReceived = _context.CartonDetails
                                .Where(s => s.PurchaseOrderSummary.PreReceiveOrder.Id == preId &&
                                       s.PurchaseOrderSummary.PurchaseOrder == po)
                                .Sum(s => s.ActualReceived);

            pl.Available = _context.CartonDetails
                           .Where(s => s.PurchaseOrderSummary.PreReceiveOrder.Id == preId &&
                                  s.PurchaseOrderSummary.PurchaseOrder == po)
                           .Sum(s => s.Available);

            //同步pcs收货总量、库存数量
            pl.ActualReceivedPcs = _context.CartonBreakDowns
                                   .Include(c => c.PurchaseOrderSummary.PreReceiveOrder)
                                   .Where(s => s.PurchaseOrderSummary.PreReceiveOrder.Id == preId &&
                                          s.PurchaseOrderSummary.PurchaseOrder == po)
                                   .Sum(s => s.ActualPcs);

            pl.AvailablePcs = _context.CartonBreakDowns
                              .Include(c => c.PurchaseOrderSummary.PreReceiveOrder)
                              .Where(s => s.PurchaseOrderSummary.PreReceiveOrder.Id == preId &&
                                     s.PurchaseOrderSummary.PurchaseOrder == po)
                              .Sum(s => s.AvailablePcs);

            _context.SaveChanges();
        }
示例#2
0
 public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
 {
     if (ModelState.IsValid)
     {
         var carton = db.Cartons
                      .Include(c => c.CartonDetails)
                      .Where(c => c.Id == addEquipmentViewModel.CartonId)
                      .SingleOrDefault();
         if (carton == null)
         {
             return(HttpNotFound());
         }
         var equipment = db.Equipments
                         .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                         .SingleOrDefault();
         if (equipment == null)
         {
             return(HttpNotFound());
         }
         var detail = new CartonDetail()
         {
             Carton    = carton,
             Equipment = equipment
         };
         carton.CartonDetails.Add(detail);
         db.SaveChanges();
     }
     return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
 }
示例#3
0
        public void Carton_ObjectCreation_Test(int medicineStripCount, string launchDate, string retailerAddress)
        {
            Medicine     medicine_carton = p.CreateMedicineDetail("Tablet_1", "Paracetamol", "MedicTab", DateTime.Parse("2022 /01/02"), 10.00);
            CartonDetail carton          = p.CreateCartonDetail(medicineStripCount, DateTime.Parse(launchDate), retailerAddress, medicine_carton);

            Assert.AreEqual(typeof(CartonDetail), carton.GetType());
        }
示例#4
0
        public void Carton_MedicineObjectNull_Test(int medicineStripCount, string launchDate, string retailerAddress)
        {
            Medicine     medicine_carton = null;
            CartonDetail d = p.CreateCartonDetail(medicineStripCount, DateTime.Parse(launchDate), retailerAddress, medicine_carton);

            Assert.AreEqual(medicine_carton, d);
        }
示例#5
0
 /// <summary>
 /// This is to add the Equipment to the Carton; if the carton is having less than 10 items
 /// </summary>
 /// <param name="addEquipmentViewModel"></param>
 /// <returns></returns>
 public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
 {
     if (addEquipmentViewModel != null)
     {
         int count = CartonBuilderSingletonUtil.Instance.getCartonCount(addEquipmentViewModel.CartonId);
         if (count < 10)
         {
             var carton = db.Cartons
                          .Include(c => c.CartonDetails)
                          .Where(c => c.Id == addEquipmentViewModel.CartonId)
                          .SingleOrDefault();
             if (carton == null)
             {
                 return(HttpNotFound());
             }
             var equipment = db.Equipments
                             .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                             .SingleOrDefault();
             if (equipment == null)
             {
                 return(HttpNotFound());
             }
             var detail = new CartonDetail()
             {
                 Carton    = carton,
                 Equipment = equipment
             };
             carton.CartonDetails.Add(detail);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
 }
示例#6
0
        public void CreateCartonDetails_NullMedicine_ReturnsNull(int medicinestripcount,
                                                                 DateTime LaunchDate, string retailerAddress, double ExpectedtotalAmount)
        {
            medicine = null;
            CartonDetail carton = program.CreateCartonDetail(medicinestripcount, LaunchDate, retailerAddress, medicine);

            Assert.IsNull(carton);
        }
示例#7
0
        public void CartonObjCreateTest(int medicineStripCount, DateTime launchDate, string retailerAddress)
        {
            CartonDetail carton = progObj.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, this.medicine);

            Assert.That(carton.MedicineStripCount, Is.EqualTo(medicineStripCount));
            Assert.That(carton.LaunchDate, Is.EqualTo(launchDate));
            Assert.That(carton.RetailerAddress, Is.EqualTo(retailerAddress));
            Assert.That(carton.Medicine, Is.EqualTo(medicine));
        }
        public void CreateCartonDetail_WhenCalled_ReturnCartonObject(int medicineStripCount, DateTime launchDate, string retailerAddress)
        {
            CartonDetail result = p.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(result.MedicineStripCount, Is.EqualTo(medicineStripCount));
            Assert.That(result.LaunchDate, Is.EqualTo(launchDate));
            Assert.That(result.RetailerAddress, Is.EqualTo(retailerAddress));
            Assert.That(result.Medicine, Is.EqualTo(m));
        }
        //[TestCase(5, "2021/08/07", "Vijaya nagar",1)]
        public void CreateCartonDetail_MedicineObjectNull_Exception(int medicineStripCount, DateTime launchDate, string retailerAddress, int n)
        {
            Program  p = new Program();
            Medicine m;

            m = get(n);
            CartonDetail res = p.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(res, Is.EqualTo(null));
        }
示例#10
0
        public void CreateCartonDetail_WhenCalledEmptyMedicine_ReturnsEmptyCartonObject(int medicineStripCount, DateTime launchDate, string retailerAddress, string key)
        {
            Medicine m;

            m = GetMedicineObject(key);

            CartonDetail result = program.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(result, Is.EqualTo(null));
        }
示例#11
0
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }

                //validate if there are more than 10 equipments in a carton
                var equipmentsCount = db.CartonDetails.Where(e => e.CartonId == addEquipmentViewModel.CartonId).Count();
                if (equipmentsCount >= 10)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Carton reaches maximum capicity, can't add more equipment!!!"));
                }

                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }

                //check if one equipment is already in this or other cartons
                var checkIfInCarton = db.CartonDetails.Where(e => e.EquipmentId == addEquipmentViewModel.EquipmentId).SingleOrDefault();
                if (checkIfInCarton != null)
                {
                    if (checkIfInCarton.CartonId == addEquipmentViewModel.CartonId)
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Equipment already exists in current carton!!!"));
                    }
                    else
                    {
                        return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Equipment already exists in carton " + checkIfInCarton.CartonId + "!!!"));
                    }
                }
                else
                {
                    var detail = new CartonDetail()
                    {
                        Carton    = carton,
                        Equipment = equipment
                    };
                    carton.CartonDetails.Add(detail);
                    db.SaveChanges();
                }
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#12
0
 public ActionResult RemoveEquipmentOnCarton([Bind(Include = "CartonId,EquipmentId")] RemoveEquipmentViewModel removeEquipmentViewModel)
 {
     //////return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     if (ModelState.IsValid)
     {
         //Remove code here
         CartonDetail cartonDetail = db.CartonDetails.Where(cd => cd.CartonId == removeEquipmentViewModel.CartonId && cd.EquipmentId == removeEquipmentViewModel.EquipmentId).Single();
         db.CartonDetails.Remove(cartonDetail);
         db.SaveChanges();
     }
     return(RedirectToAction("ViewCartonEquipment", new { id = removeEquipmentViewModel.CartonId }));
 }
        public void CreateCartonDetail_WhenCalled_ReturnCartonObject(int medicineStripCount, DateTime launchDate, string retailerAddress, int n)
        {
            Program  p = new Program();
            Medicine m;

            m = get(n);
            CartonDetail res = p.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(res.MedicineStripCount, Is.EqualTo(medicineStripCount));
            Assert.That(res.LaunchDate, Is.EqualTo(launchDate));
            Assert.That(res.RetailerAddress, Is.EqualTo(retailerAddress));
        }
示例#14
0
        public void CreateCartonDetail_WhenCalled_ReturnCartonObject(int medicineStripCount, DateTime launchDate, string retailerAddress, string key)
        {
            Program pro = new Program();

            Medicine m;

            m = GetMedicineObject(key);

            CartonDetail result = pro.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(result.MedicineStripCount, Is.EqualTo(medicineStripCount));
            Assert.That(result.LaunchDate, Is.EqualTo(launchDate));
        }
示例#15
0
        public void CartonDetail_Called_CreateAndReturnObject(int medicineStripCount, DateTime launchDate, string retailerAddress, string key)
        {
            Medicine m;

            m = GetMedicineObject(key);

            CartonDetail result = program.CreateCartonDetail(medicineStripCount, launchDate, retailerAddress, m);

            Assert.That(result.MedicineStripCount, Is.EqualTo(medicineStripCount));
            Assert.That(result.RetailerAddress, Is.EqualTo(retailerAddress));
            Assert.That(result.LaunchDate, Is.EqualTo(launchDate));
            Assert.That(result.Medicine, Is.EqualTo(m));
        }
示例#16
0
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton != null)
                {
                    var cart = carton.CartonDetails.Where(x => x.EquipmentId == addEquipmentViewModel.EquipmentId).ToList();
                    if (cart.Count == 0)
                    {
                        //cart items count
                        if (carton.CartonDetails.ToList().Count < 10)
                        {
                            var equipment = db.Equipments
                                            .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                            .SingleOrDefault();
                            if (equipment == null)
                            {
                                return(HttpNotFound());
                            }
                            var detail = new CartonDetail()
                            {
                                Carton    = carton,
                                Equipment = equipment
                            };
                            carton.CartonDetails.Add(detail);
                            db.SaveChanges();
                            return(RedirectToAction("Index"));
                        }
                        else
                        {
                            //cart already contains 10 items, cannot add more equipments
                            addEquipmentViewModel.Error = "cart already contains 10 items, cannot add more equipments";
                            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, addEquipmentViewModel.Error }));
                        }
                    }
                    else
                    {
                        addEquipmentViewModel.Error = "Equipment already exist in the cart";
                        return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, addEquipmentViewModel.Error }));
                        //Equipment already exist in the cart
                    }

                    return(HttpNotFound());
                }
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#17
0
        [TestCase(1, "10/04/2021", "Retailer address")]//with all right details provided
        public void CheckCortonObjectCreation(int count, DateTime launchYears, string address)
        {
            CartonDetail c = null;

            try
            {
                c = p.CreateCartonDetail(count, launchYears, address, medicine);
                Assert.IsNotNull(c);
            }
            catch
            {
                Assert.Fail("Corton Object not created successfully");
            }
        }
示例#18
0
 /// <summary>
 /// This is to remove the Equipment from the Carton by the Carton Id and Equipment ID
 /// </summary>
 /// <param name="removeEquipmentViewModel"></param>
 /// <returns></returns>
 public ActionResult RemoveEquipmentOnCarton([Bind(Include = "CartonId,EquipmentId")] RemoveEquipmentViewModel removeEquipmentViewModel)
 {
     //return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     if (ModelState.IsValid)
     {
         CartonDetail cartonDetail = db.CartonDetails.SingleOrDefault(c => c.EquipmentId == removeEquipmentViewModel.EquipmentId);
         if (cartonDetail != null)
         {
             db.CartonDetails.Remove(cartonDetail);
             db.SaveChanges();
         }
     }
     return(RedirectToAction("ViewCartonEquipment", new { id = removeEquipmentViewModel.CartonId }));
 }
        //[TestCase(0, "10/04/2021", "Retailer address")]
        //[TestCase(12, "11/02/2020", "Retailer address"]



        public void CheckCortonObjectCreation(int Count, DateTime LaunchDate, string Address)
        {
            CartonDetail c = null;

            try
            {
                c = p.CreateCartonDetail(Count, LaunchDate, Address, med);
                Assert.IsNotNull(c);
            }
            catch
            {
                Assert.Fail("Corton Object not created successfully");
            }
        }
示例#20
0
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }

                if (carton.CartonDetails.Count() >= 10) // DM: hardcoded 10, would make more sense to put this in the DB as a config option of the carton, but trying to keep this to the 1 hour mark.
                                                        // You could then use that in the config value to set the MaxCurrentEquipmentCount I added in the CartonDetailsViewModel.
                {
                    TempData["Message"] = "Your equipment was not added because the carton already has the maximum amount of items.";
                    return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
                }

                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }

                var assignedEquipement = db.CartonDetails
                                         .Where(cd => cd.EquipmentId == addEquipmentViewModel.EquipmentId)
                                         .SingleOrDefault();
                if (assignedEquipement != null)
                {
                    TempData["Message"] = "Your equipment has already been added to another carton.";
                    return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
                }

                var detail = new CartonDetail()
                {
                    Carton    = carton,
                    Equipment = equipment
                };

                carton.CartonDetails.Add(detail);
                db.SaveChanges();
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#21
0
        public string TestCartonDetails(int medicineStripCount, string launchDate, string retailerAddress)

        {
            DateTime datetime = DateTime.Parse(launchDate);
            var      medicine = new Medicine()
            {
                Name = "Dolo",
                GenericMedicineName = "Dolo650",
                Composition         = "Dolo",
                ExpiryDate          = DateTime.Parse("02-02-2030"),
                PricePerStrip       = 50
            };
            CartonDetail carton = program.CreateCartonDetail(medicineStripCount, datetime, retailerAddress, medicine);
            string       result = string.Format("{0},{1},{2}", carton.MedicineStripCount, carton.LaunchDate.ToShortDateString(), carton.RetailerAddress.Trim());

            return(result);
        }
示例#22
0
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }
                //AM: TODO BUG3 = DONT ALLOW USER TO ADD MORE THAN 10 Equipment to a carton - DONE
                //Check if carton is at capacity
                if (carton.CartonDetails.Count == 10)
                {
                    return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, valMsg = ErrMsgcd1 }));
                }

                var ExistingEquipment = db.CartonDetails
                                        .Where(cd => cd.EquipmentId == addEquipmentViewModel.EquipmentId)
                                        .SingleOrDefault();

                //AM: TODO BUG2 =  Equipment already part of any other Carton  - DONE
                if (ExistingEquipment != null)
                {
                    return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, valMsg = ErrMsgcd2 }));
                }

                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }
                var detail = new CartonDetail()
                {
                    Carton    = carton,
                    Equipment = equipment
                };
                carton.CartonDetails.Add(detail);
                db.SaveChanges();
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#23
0
        /*
         *  2 - Our customers has reported the following bugs:
         *      3. Our cartons can physically hold up to 10 pieces of equipment, but the application allows us to
         *      put an unlimited number of equipment on the carton, please only allow up to 10 pieces of
         *      equipment on the carton.
         *
         */
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }
                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }
                var detail = new CartonDetail()
                {
                    Carton    = carton,
                    Equipment = equipment
                };

                //KF: solution to issue 2.2
                //check first if this equipment is already added
                if (db.CartonDetails.Where(e => e.EquipmentId == equipment.Id).Count() == 0)
                {
                    //check the carton detail count - must be lesser than 10
                    if (carton.CartonDetails.Count < _CartonLimit)
                    {
                        carton.CartonDetails.Add(detail);
                        db.SaveChanges();
                    }
                }
                else
                {
                    //notify the user that the equipment is already assigned
                    TempData["Error"] = equipment.SerialNumber + " is already in use.";
                }
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#24
0
        public void CreateCartonDetails_CorrectValues_ReturnValid(int medicinestripcount,
                                                                  DateTime LaunchDate, string retailerAddress, double ExpectedtotalAmount)
        {
            Console.WriteLine("Expiry Date : " + medicine.ExpiryDate);
            Console.WriteLine("Launch Date : " + LaunchDate);
            CartonDetail carton = program.CreateCartonDetail(medicinestripcount, LaunchDate, retailerAddress, medicine);

            //test for medicine equality
            Assert.That(carton, Is.TypeOf <CartonDetail>());
            Assert.AreEqual(carton.Medicine.Name, medicine.Name);
            Assert.AreEqual(carton.Medicine.GenericMedicineName, medicine.GenericMedicineName);
            Assert.AreEqual(carton.Medicine.Composition, medicine.Composition);
            Assert.AreEqual(carton.Medicine.ExpiryDate, medicine.ExpiryDate);
            Assert.AreEqual(carton.Medicine.PricePerStrip, medicine.PricePerStrip);

            Assert.AreEqual(medicinestripcount, carton.MedicineStripCount);
            Assert.AreEqual(LaunchDate, carton.LaunchDate);
            Assert.AreEqual(retailerAddress, carton.RetailerAddress);
            Assert.AreEqual(ExpectedtotalAmount, carton.TotalAmount);
        }
        //每确认一次carton收取情况,同步一次该PreRecieveOrder的ctn收货总量、库存数量及pcs收货总量、
        //库存数量
        public void SyncPreReceivedOrder(CartonDetail cartonDetailSample)
        {
            var pl               = cartonDetailSample.PurchaseOrderSummary;
            var po               = pl.PurchaseOrder;
            var preId            = pl.PreReceiveOrder.Id;
            var preReceivedOrder = pl.PreReceiveOrder;

            //同步一次该preReceivedOrder的ctn收货总量、库存数量
            preReceivedOrder.ActualReceivedCtns = _context.PurchaseOrderSummaries
                                                  .Include(s => s.PreReceiveOrder)
                                                  .Where(s => s.PreReceiveOrder.Id == preId)
                                                  .Sum(s => s.ActualReceived);

            //同步一次该preReceivedOrder的pcs收货总量、库存数量
            preReceivedOrder.ActualReceivedPcs = _context.PurchaseOrderSummaries
                                                 .Include(s => s.PreReceiveOrder)
                                                 .Where(s => s.PreReceiveOrder.Id == preId)
                                                 .Sum(s => s.ActualReceivedPcs);

            _context.SaveChanges();
        }
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }
                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }
                var detail = new CartonDetail()
                {
                    Carton    = carton,
                    Equipment = equipment
                };

                //Customer Requirement 3 : A cartonm will be limited to only 10 items, by using the below line of code.

                if (((System.Collections.Generic.HashSet <CandidateProject.EntityModels.CartonDetail>)carton.CartonDetails).Count < 10)
                {
                    carton.CartonDetails.Add(detail);
                    db.SaveChanges();
                }
                else
                {
                    ViewBag.Message = "Sorry,Carton exceed 10 equipments";
                }
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
        //Last remaining Item for the iteration to removeEquipment On Carton.

        public ActionResult RemoveEquipmentOnCarton([Bind(Include = "CartonId,EquipmentId")] RemoveEquipmentViewModel removeEquipmentViewModel)
        {
            var carton = db.Cartons
                         .Include(c => c.CartonDetails)
                         .Where(c => c.Id == removeEquipmentViewModel.CartonId)
                         .SingleOrDefault();

            if (carton == null)
            {
                return(HttpNotFound());
            }
            var equipment = db.Equipments
                            .Where(e => e.Id == removeEquipmentViewModel.EquipmentId)
                            .SingleOrDefault();

            if (equipment == null)
            {
                return(HttpNotFound());
            }

            var cartondetailID = db.CartonDetails
                                 .Where(cd => cd.EquipmentId == equipment.Id)
                                 .SingleOrDefault();

            var detail = new CartonDetail()
            {
                Carton    = carton,
                Equipment = equipment
            };

            CartonDetail cartondetail = db.CartonDetails.Find(cartondetailID.Id);

            db.CartonDetails.Remove(cartondetail);

            db.SaveChanges();
            return(RedirectToAction("ViewCartonEquipment", new { id = removeEquipmentViewModel.CartonId }));
        }
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            if (ModelState.IsValid)
            {
                var carton = db.Cartons
                             .Include(c => c.CartonDetails)
                             .Where(c => c.Id == addEquipmentViewModel.CartonId)
                             .SingleOrDefault();
                if (carton == null)
                {
                    return(HttpNotFound());
                }
                var equipment = db.Equipments
                                .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                .SingleOrDefault();
                if (equipment == null)
                {
                    return(HttpNotFound());
                }

                if (carton.CartonDetails.Count() >= 10)
                {
                    TempData["notice"] = "Carton is full, please only allow up to 10 pieces of equipment on the carton";
                    return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
                }

                var detail = new CartonDetail()
                {
                    Carton    = carton,
                    Equipment = equipment
                };
                carton.CartonDetails.Add(detail);
                db.SaveChanges();
            }
            return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId }));
        }
示例#29
0
        public ActionResult AddEquipmentToCarton([Bind(Include = "CartonId,EquipmentId")] AddEquipmentViewModel addEquipmentViewModel)
        {
            try
            {
                string dialogText = string.Empty;

                //Bug #3: in case max carton volume changes, max count is a key in the web.config
                int maxItemCount = 0;
                //if the key is missing default to 10
                if (!int.TryParse(ConfigurationManager.AppSettings["MaxItemsPerCarton"].ToString(), out maxItemCount))
                {
                    maxItemCount = 10;
                }

                //Bug #2: currently a piece of equipment can only be in one carton, there is a key to toggle that option in web.config
                bool multipleCartons = false;
                //if key is missing or an invalid type default is false
                if (!bool.TryParse(ConfigurationManager.AppSettings["AllowItemInMultipleCartons"].ToString(), out multipleCartons))
                {
                    multipleCartons = false;
                }

                if (ModelState.IsValid)
                {
                    var carton = db.Cartons
                                 .Include(c => c.CartonDetails)
                                 .Where(c => c.Id == addEquipmentViewModel.CartonId)
                                 .SingleOrDefault();
                    if (carton == null)
                    {
                        return(RedirectToAction("NotFound", "Error"));
                    }

                    //Bug #2: check all cartons to see if this equipment has already been added to another one
                    var currentEquipment = db.CartonDetails
                                           .Where(c => c.EquipmentId == addEquipmentViewModel.EquipmentId)
                                           .SingleOrDefault();

                    if (currentEquipment != null && !multipleCartons)
                    {
                        dialogText = "This item has already been added to another carton.";
                        return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, serialNumber = string.Empty, errorMessage = dialogText }));
                    }

                    //Bug #3: make sure there aren't more than 10 (value stored in maxItemCount) items in this carton already
                    var cartonDetails = db.CartonDetails.Where(e => e.CartonId == addEquipmentViewModel.CartonId).ToList();

                    if (cartonDetails == null || cartonDetails.Count < maxItemCount)
                    {
                        var equipment = db.Equipments
                                        .Include("ModelType")
                                        .Where(e => e.Id == addEquipmentViewModel.EquipmentId)
                                        .SingleOrDefault();
                        if (equipment == null)
                        {
                            return(RedirectToAction("NotFound", "Error"));
                        }
                        var detail = new CartonDetail()
                        {
                            Carton    = carton,
                            Equipment = equipment
                        };
                        carton.CartonDetails.Add(detail);
                        db.SaveChanges();
                        return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, equipmentDetail = string.Format("{0} {1}", equipment.ModelType.TypeName, equipment.SerialNumber) }));
                    }
                    else
                    {
                        dialogText = string.Format("This carton is full and contains {0} items. Please select another carton.", maxItemCount.ToString());
                    }
                }
                // will only make it here if the carton is full, outside of main if so all paths return an action
                return(RedirectToAction("AddEquipment", new { id = addEquipmentViewModel.CartonId, serialNumber = string.Empty, errorMessage = dialogText }));
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
                throw ex;
            }
        }
示例#30
0
        public void NullCartonDetailsTest(int medicineStripCount, string launchDate, string retailerAddress, Medicine medicine)
        {
            CartonDetail carton = progObj.CreateCartonDetail(medicineStripCount, DateTime.Parse(launchDate), retailerAddress, medicine);

            Assert.That(carton, Is.EqualTo(null));
        }