Esempio n. 1
0
        public virtual ActionResult AcceptPallet(PalletViewModel mm)
        {
            //TC5 : Scan null or empty in textbox on Pallet page.
            if (string.IsNullOrEmpty(mm.ScannedPalletId))
            {
                return(RedirectToAction(Actions.AcceptBuilding()));
            }
            mm.ScannedPalletId = mm.ScannedPalletId.ToUpper();
            //TC6 : Scan a invalid pallet i.e. a pallet that do not starts with P
            if (!ModelState.IsValid)
            {
                return(View(Views.Pallet, mm));
            }

            Pallet pallet = null;
            var    fieldScannedPalletId = mm.NameFor(m => m.ScannedPalletId);

            try
            {
                pallet = _repos.Value.RetrievePalletInfo(mm.ScannedPalletId);
                //TC7 : Scan a new pallet to create ADR pallet.
                if (pallet == null)
                {
                    return(RedirectToAction(MVC_BoxPick.BoxPick.Confirm.Actions.ADRPallet(mm.ScannedPalletId)));
                }
                //TC8 : Scan a pallet for which TotalBoxes are equal to PickedBoxes
                else if (pallet.IsFull)
                {
                    this.AddStatusMessage(string.Format("Pallet {0} has been already picked.", mm.ScannedPalletId));
                    return(RedirectToAction(MVC_BoxPick.BoxPick.Confirm.Print(mm.ScannedPalletId)));
                }
                //TC9 : Scan a pallet that doesnot belongs to current scanned building
                else if (pallet.BuildingId != mm.CurrentBuildingId)
                {
                    ModelState.AddModelError(fieldScannedPalletId, string.Format("Pallet {0} is for building {1} and not for current building {2}, Please scan new pallet",
                                                                                 mm.ScannedPalletId, pallet.BuildingId, mm.CurrentBuildingId));
                }
                //TC10 : If we don't enter any area then scanned pallet area will be treated as current source area.
                else if (string.IsNullOrEmpty(mm.CurrentSourceArea))
                {
                    // We have chosen the area on user's behalf
                    mm.CurrentSourceArea          = pallet.CartonSourceArea;
                    mm.CurrentSourceAreaShortName = pallet.SourceAreaShortName;
                }
                //TC11 : If scanned palletArea is not same as currten pallet area
                else if (pallet.CartonSourceArea != mm.CurrentSourceArea)
                {
                    // Pallet must be of the correct destination area
                    ModelState.AddModelError(fieldScannedPalletId, string.Format("Pallet {0} is for area {1} and not for current area {2}, Please scan new pallet",
                                                                                 mm.ScannedPalletId, pallet.SourceAreaShortName, mm.CurrentSourceAreaShortName));
                }
                //Showing cartons destination area in where the carton to picked
                mm.CurrentDestinationArea   = pallet.DestinationArea;
                mm.CurrentDestAreaShortName = pallet.DestAreaShortName;
            }
            catch (DbException ex)
            {
                ModelState.AddModelError(fieldScannedPalletId, ex.Message);
            }

            var model = new MasterModelWithPallet(this.HttpContext.Session);

            if (ModelState.IsValid)
            {
                model.Map(pallet);
                TryValidateModel(model, fieldScannedPalletId);
            }

            if (!ModelState.IsValid || pallet.IsFull)
            {
                model.Map(null);
                return(View(Views.Pallet, mm));
            }

            return(View(Views.Carton, new CartonViewModel(this.HttpContext.Session)));
        }