Ejemplo n.º 1
0
        public virtual ActionResult Wave(int bucketId, SuggestedNextActionType suggestedNextAction)
        {
            var bucket = _service.GetBucket(bucketId);

            if (bucket == null)
            {
                // Unreasonable bucket id
                //ModelState.AddModelError("", string.Format("Pick Wave {0} is deleted", model.Bucket.BucketId));
                return(RedirectToAction(MVC_PickWaves.PickWaves.Home.Index()));
            }
            var model = new WaveViewModel();

            model.Bucket = new BucketModel(bucket);

            // If Bucket is pulling bucket and value of PullingBucket is N. then Bucket Required Box Expediting
            if (!string.IsNullOrWhiteSpace(bucket.PullingBucket) && bucket.PullingBucket == "N")
            {
                model.Bucket.RequiredBoxExpediting = true;
            }
            if (!model.Bucket.IsFrozen)
            {
                model.HighlightedActions = SuggestedNextActionType.UnfreezeOthers;
            }
            return(View(this.Views.Wave, model));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns flags corresponding to changed values. Compares original values with current values.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private EditBucketFlags GetEditFlags(WaveViewModel model)
        {
            var flags = EditBucketFlags.None;

            if (model.BucketNameOriginal != model.Bucket.BucketName)
            {
                flags |= EditBucketFlags.BucketName;
            }
            if (model.PriorityIdOriginal != model.Bucket.PriorityId)
            {
                flags |= EditBucketFlags.Priority;
            }
            if (model.PullAreaOriginal != model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pulling).AreaId)
            {
                flags |= EditBucketFlags.PullArea;
            }
            if (model.PitchAreaOriginal != model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pitching).AreaId)
            {
                flags |= EditBucketFlags.PitchArea;
            }
            if (model.BucketCommentOriginal != model.Bucket.BucketComment)
            {
                flags |= EditBucketFlags.Remarks;
            }
            if (model.QuickPitchOriginal != model.Bucket.QuickPitch && !string.IsNullOrWhiteSpace(model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pitching).AreaId))
            {
                flags |= EditBucketFlags.QuickPitch;
            }
            if (model.PitchLimitOriginal != model.Bucket.PitchLimit && !string.IsNullOrWhiteSpace(model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pitching).AreaId))
            {
                flags |= EditBucketFlags.PitchLimit;
            }
            flags |= EditBucketFlags.PullType;
            return(flags);
        }
Ejemplo n.º 3
0
        public virtual ActionResult EditWave(int bucketId, SuggestedNextActionType suggestedNextAction)
        {
            //if (!ModelState.IsValid)
            //  {
            //      return RedirectToAction(this.Actions.EditableWave(new WaveViewModel(model.Bucket.BucketId, SuggestedNextActionType.CancelEditing)));
            //  }

            if (!ModelState.IsValid)
            {
                return(RedirectToAction(this.Actions.EditableWave(bucketId, SuggestedNextActionType.CancelEditing)));
            }

            var model = new WaveViewModel();
            var count = model.Bucket.Activities.Count(p => !string.IsNullOrWhiteSpace(p.AreaId));

            if (count == 0 && model.UnfreezeWaveAfterSave)
            {
                // Bucket have not any area for pulling and / pitching.
                ModelState.AddModelError("", "Pick wave could not be updated. Please gave at least one area for pulling and/ pitching and try again");
                return(RedirectToAction(this.Actions.EditableWave(model.Bucket.BucketId, SuggestedNextActionType.CancelEditing)));
            }

            var pullAreaId  = model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pulling).AreaId;
            var pitchAreaId = model.Bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pitching).AreaId;
            var bucket      = new Bucket
            {
                BucketId      = model.Bucket.BucketId,
                BucketName    = model.Bucket.BucketName,
                PriorityId    = model.Bucket.PriorityId,
                BucketComment = model.Bucket.BucketComment,
                QuickPitch    = !string.IsNullOrEmpty(pitchAreaId) && model.Bucket.QuickPitch
            };

            if (!string.IsNullOrEmpty(pitchAreaId) && model.Bucket.PitchLimit != null)
            {
                bucket.PitchLimit = model.Bucket.PitchLimit;
            }

            // For manage PullToDock flag. In case of pulling, PullToDock is not null.
            if (!string.IsNullOrEmpty(pullAreaId))
            {
                if (model.Bucket.RequiredBoxExpediting)
                {
                    bucket.PullingBucket = "N";
                }
                else
                {
                    bucket.PullingBucket = "Y";
                }
            }
            // In case of pitching, PullToDock is null.
            else
            {
                bucket.PullingBucket = null;
            }

            bucket.Activities[BucketActivityType.Pulling].Area.AreaId  = pullAreaId;
            bucket.Activities[BucketActivityType.Pitching].Area.AreaId = pitchAreaId;
            var bucketOld = new Bucket
            {
                BucketId              = model.Bucket.BucketId,
                BucketName            = model.BucketNameOriginal,
                PriorityId            = model.PriorityIdOriginal,
                RequiredBoxExpediting = model.RequiredBoxExpeditingOriginal,
                BucketComment         = model.BucketCommentOriginal,
                QuickPitch            = model.QuickPitchOriginal,
                PitchLimit            = model.PitchLimitOriginal
            };

            bucketOld.Activities[BucketActivityType.Pulling].Area.AreaId  = model.PullAreaOriginal;
            bucketOld.Activities[BucketActivityType.Pitching].Area.AreaId = model.PitchAreaOriginal;
            try
            {
                _service.EditWave(bucket, GetEditFlags(model), bucketOld);
                AddStatusMessage(string.Format("Pick Wave {0} updated.", model.Bucket.BucketId));
            }
            catch (DbException ex)
            {
                ModelState.AddModelError("", "Pick wave could not be updated. Please review the error and try again");
                ModelState.AddModelError("", ex.Message);
                return(RedirectToAction(this.Actions.EditableWave(model.Bucket.BucketId, SuggestedNextActionType.NotSet)));
            }
            catch (ValidationException ex)
            {
                ModelState.AddModelError("", ex.Message);
                return(RedirectToAction(this.Actions.EditableWave(model.Bucket.BucketId, SuggestedNextActionType.NotSet)));
            }
            if (model.UnfreezeWaveAfterSave)
            {
                //  if user says unfreeze bucket after editing.
                _service.FreezeWave(model.Bucket.BucketId, false);
                AddStatusMessage(string.Format("Pick wave {0} has been unfrozen.", model.Bucket.BucketId));
                return(RedirectToAction(this.Actions.Wave(model.Bucket.BucketId, SuggestedNextActionType.UnfreezeOthers)));
            }
            return(RedirectToAction(this.Actions.Wave(model.Bucket.BucketId, SuggestedNextActionType.UnfreezeMe)));
        }
Ejemplo n.º 4
0
        public virtual ActionResult EditableWave(int bucketId, SuggestedNextActionType suggestedNextAction)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(MVC_PickWaves.PickWaves.Home.Index()));
            }
            var bucket = _service.GetBucket(bucketId);

            if (bucket == null)
            {
                // Unreasonable bucket id
                ModelState.AddModelError("", string.Format("Unreasonable Pick Wave {0}", bucketId));
                return(RedirectToAction(MVC_PickWaves.PickWaves.Home.Index()));
            }
            if (!bucket.IsFrozen)
            {
                // bucket is not freeze,freeze it before attempting to edit it.
                ModelState.AddModelError("", "Please freeze the pick wave before attempting to edit it");
                return(RedirectToAction(Actions.Wave(bucketId, SuggestedNextActionType.NotSet)));
            }

            var model = new WaveViewModel();

            model.Bucket = new BucketModel(bucket);

            var bucketAreas = _service.GetBucketAreas(model.Bucket.BucketId);

            model.BucketAreaLists = new Dictionary <BucketActivityType, IList <SelectListItem> >
            {
                {
                    BucketActivityType.Pulling,
                    (from area in bucketAreas
                     where area.AreaType == BucketActivityType.Pulling
                     orderby area.CountSku descending
                     select new SelectListItem
                    {
                        Text = string.Format("{0}: {1} ({2:N0}% SKUs available)", area.ShortName ?? area.AreaId, area.Description, area.CountOrderedSku == 0 ? 0 : area.CountSku * 100 / area.CountOrderedSku),
                        Value = area.CountSku > 0 ? area.AreaId : "",
                        Selected = area.AreaId == bucket.Activities[BucketActivityType.Pulling].Area.AreaId
                    }).ToArray()
                },
                {
                    BucketActivityType.Pitching,
                    (from area in bucketAreas
                     where area.AreaType == BucketActivityType.Pitching
                     orderby area.CountSku descending
                     select new SelectListItem
                    {
                        Text = string.Format("{0}: {1} ({2:N0}% SKUs assigned.)", area.ShortName ?? area.AreaId, area.Description, area.CountOrderedSku == 0 ? 0 : area.CountSku * 100 / area.CountOrderedSku),
                        Value = area.CountSku > 0 ? area.AreaId : "",
                        Selected = area.AreaId == bucket.Activities[BucketActivityType.Pitching].Area.AreaId
                    }).ToArray()
                }
            };

            //For Pull area
            if (model.BucketAreaLists[BucketActivityType.Pulling].Any(p => string.IsNullOrWhiteSpace(p.Value)))
            {
                // We have some areas with no ordered SKUs
                model.BucketAreaLists[BucketActivityType.Pulling] = model.BucketAreaLists[BucketActivityType.Pulling].Where(p => !string.IsNullOrWhiteSpace(p.Value)).ToList();
                if (!model.BucketAreaLists[BucketActivityType.Pulling].Any())
                {
                    // We do have pull areas but none with SKUs needed
                    model.BucketAreaLists[BucketActivityType.Pulling].Add(new SelectListItem
                    {
                        Text     = "(Ordered SKUs are not available in any Pull Area)",
                        Value    = "",
                        Selected = true
                    });
                }
            }

            //For Pitch area
            if (model.BucketAreaLists[BucketActivityType.Pitching].Any(p => string.IsNullOrWhiteSpace(p.Value)))
            {
                // We have some areas with no ordered SKUs
                model.BucketAreaLists[BucketActivityType.Pitching] = model.BucketAreaLists[BucketActivityType.Pitching].Where(p => !string.IsNullOrWhiteSpace(p.Value)).ToList();
                if (!model.BucketAreaLists[BucketActivityType.Pitching].Any())
                {
                    // We do have pitch areas but none with SKUs needed
                    model.BucketAreaLists[BucketActivityType.Pitching].Add(new SelectListItem
                    {
                        Text     = "(Ordered SKUs are not assigned in any Pitch Area)",
                        Value    = "",
                        Selected = true
                    });
                }
            }

            // For edit wave
            model.DisplayEditableWave   = true;
            model.BucketNameOriginal    = bucket.BucketName;
            model.PriorityIdOriginal    = bucket.PriorityId;
            model.PullAreaOriginal      = bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pulling).Area.AreaId;
            model.PitchAreaOriginal     = bucket.Activities.Single(p => p.ActivityType == BucketActivityType.Pitching).Area.AreaId;
            model.BucketCommentOriginal = bucket.BucketComment;
            model.QuickPitchOriginal    = bucket.QuickPitch;
            model.PitchLimitOriginal    = bucket.PitchLimit;

            if (!string.IsNullOrWhiteSpace(bucket.PullingBucket) && bucket.PullingBucket == "N")
            {
                // If pulling bucket
                model.Bucket.RequiredBoxExpediting  = true;
                model.RequiredBoxExpeditingOriginal = true;
            }
            return(View(this.Views.Wave, model));
        }