Exemplo n.º 1
0
        public virtual ActionResult ADRPallet(string palletId)
        {
            var model = new ADRPalletViewModel(this.Session)
            {
                ConfirmPalletId = palletId
            };

            return(View(Views.ADRPallet, model));
        }
Exemplo n.º 2
0
        public virtual ActionResult ConfirmADRPallet(ADRPalletViewModel model)
        {
            //Sent to pallet scan
            //TC 30 : Scan null in confirm screen to create new ADR pallet
            if (string.IsNullOrEmpty(model.Scan))
            {
                return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptPallet()));
            }

            //TC 31 : Enter different pallet Id in confirm screen to create new pallet
            if (model.ConfirmPalletId != model.Scan)
            {
                this.AddStatusMessage("The confirmation pallet did not match the original pallet.");
                return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptPallet()));
            }

            //Create pallet for ADR
            try
            {
                int rowsAffected = _repos.Value.CreateADRPallet(model.ConfirmPalletId, model.CurrentBuildingId, model.CurrentDestinationArea);
                if (rowsAffected == 0)
                {
                    this.AddStatusMessage(string.Format("No cartons to pick for building {0}{1}", model.CurrentBuildingId,
                                                        !string.IsNullOrEmpty(model.CurrentDestAreaShortName) ? string.Format(", area {0}", model.CurrentDestAreaShortName) : string.Empty));
                    return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptPallet()));
                }
                this.AddStatusMessage(string.Format("{0:d} carton to be picked", rowsAffected));
            }
            catch (DbException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            //Sent to pallet scan, CreateADRPallet should return exception when not able to create pallet
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptPallet()));
            }

            Pallet pallet = null;

            try
            {
                pallet = _repos.Value.RetrievePalletInfo(model.ConfirmPalletId);
                if (pallet == null)
                {
                    ModelState.AddModelError("", "No cartons to pick");
                }
                else if (pallet.IsFull)
                {
                    //This is defensive check
                    this.AddStatusMessage(string.Format("Pallet {0} has been already picked. Please scan new pallet.", model.ConfirmPalletId));
                }
                else if (pallet.BuildingId != model.CurrentBuildingId)
                {
                    ModelState.AddModelError("", string.Format("Pallet {0} is for building {1} and not for current building {2}, Please scan new pallet",
                                                               model.ConfirmPalletId, pallet.BuildingId, model.CurrentBuildingId));
                }
                else if (string.IsNullOrEmpty(model.CurrentSourceArea))
                {
                    // We have chosen the area on user's behalf
                    model.CurrentSourceArea          = pallet.CartonSourceArea;
                    model.CurrentSourceAreaShortName = pallet.SourceAreaShortName;
                }
                else if (pallet.CartonSourceArea != model.CurrentSourceArea)
                {
                    // Pallet must be of the correct source area
                    ModelState.AddModelError("", string.Format("Pallet {0} is for area {1} and not for current area {2}, Please scan new pallet",
                                                               model.ConfirmPalletId, pallet.SourceAreaShortName, model.CurrentSourceAreaShortName));
                }
                //Showing cartons destination area in where the carton to picked
                model.CurrentDestinationArea   = pallet.DestinationArea;
                model.CurrentDestAreaShortName = pallet.DestAreaShortName;
            }
            catch (DbException ex)
            {
                ModelState.AddModelError("", ex.Message);
            }

            MasterModelWithPallet mm = new MasterModelWithPallet(this.HttpContext.Session);

            if (ModelState.IsValid)
            {
                mm.Map(pallet);
                TryValidateModel(mm);
            }

            if (!ModelState.IsValid || pallet.IsFull)
            {
                mm.Map(null);
                return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptPallet()));
            }
            return(RedirectToAction(MVC_BoxPick.BoxPick.Home.AcceptCarton()));
        }