public virtual ActionResult UpdateWave(WaveEditorViewModel model) { if (!ModelState.IsValid) { PopulateWaveEditorViewModel(model); return(View(Views.WaveEditor, model)); } var bucket = new BucketEditable { //BucketId = model.BucketId, BucketName = model.BucketName, //PriorityId = model.PriorityId, BucketComment = model.BucketComment, QuickPitch = model.QuickPitch, PitchLimit = model.PitchLimit.Value, RequireBoxExpediting = model.RequiredBoxExpediting, PullAreaId = model.PullAreaId, PitchAreaId = model.PitchAreaId }; try { using (var trans = _service.Value.BeginTransaction()) { _service.Value.UpdateWave(model.BucketId, bucket, trans); if (model.UnfreezeWaveAfterSave) { // if user says unfreeze bucket after editing. _service.Value.UnfreezePickWave(model.BucketId, trans); } trans.Commit(); } AddStatusMessage(string.Format("Pick Wave {0} updated.", model.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.BucketId, SuggestedNextActionType.NotSet)); return(RedirectToAction(this.Actions.WavePickslips(model.BucketId))); } catch (ValidationException ex) { ModelState.AddModelError("", ex.Message); //return RedirectToAction(this.Actions.EditableWave(model.BucketId, SuggestedNextActionType.NotSet)); return(RedirectToAction(this.Actions.WavePickslips(model.BucketId))); } return(RedirectToAction(this.Actions.WavePickslips(model.BucketId))); }
public virtual ActionResult WaveEditor(int bucketId) { var bucket = _service.Value.GetEditableBucket(bucketId); if (bucket == null) { // Unreasonable bucket id ModelState.AddModelError("", string.Format("Unreasonable Pick Wave {0}", bucketId)); return(RedirectToAction(MVC_PickWaves.PickWaves.Home.Customers())); } 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.WavePickslips(bucketId))); } //var bucketAreas = _service.Value.GetBucketAreas(bucketId); var model = new WaveEditorViewModel(bucket); PopulateWaveEditorViewModel(model); //{ // // Show only those areas which have some SKUs available // PullAreaList = (from area in bucketAreas // where area.AreaType == BucketActivityType.Pulling && area.CountOrderedSku.HasValue && area.CountOrderedSku.Value > 0 && // area.CountSku.HasValue && area.CountSku > 0 // orderby area.CountSku descending // let pctSkuAvailable = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value // 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.AreaId, // Selected = area.AreaId == bucket.PullAreaId // }).ToList(), // PitchAreaList = (from area in bucketAreas // where area.AreaType == BucketActivityType.Pitching && area.CountOrderedSku.HasValue && area.CountOrderedSku.Value > 0 && // area.CountSku.HasValue && area.CountSku > 0 // orderby area.CountSku descending // let pctSkuAssigned = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value // select new SelectListItem // { // Text = string.Format("{0}: {1} ({2:N0}% SKUs assigned.)", area.ShortName ?? area.AreaId, area.Description, pctSkuAssigned), // Value = area.AreaId, // Selected = area.AreaId == bucket.PitchAreaId // }).ToList(), // CustomerName = _service.Value.GetCustomerName(bucket.CustomerId) //}; return(View(Views.WaveEditor, model)); }
/// <summary> /// Populates the area lists in the passed model. The model must at least contain the bucket id. If customer id is in the model, the customer name is populated as well. /// You should also pass the Customer Id within the model. It is needed if model validation fails /// </summary> /// <param name="?"></param> private void PopulateWaveEditorViewModel(WaveEditorViewModel model) { var bucketAreas = _service.Value.GetBucketAreas(model.BucketId); var groups = bucketAreas.Select(p => p.BuildingId).Distinct().Select(p => new SelectListGroup { Name = p }).ToDictionary(p => p.Name); var allAreas = from area in bucketAreas where area.CountOrderedSku.HasValue && area.CountOrderedSku.Value > 0 && area.CountSku.HasValue && area.CountSku > 0 orderby area.BuildingId, area.CountSku descending let pctSkuAvailable = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value select new { AreaId = area.AreaId, AreaType = area.AreaType, ShortName = area.ShortName ?? area.AreaId, Description = area.Description, PctSkuAvailable = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value, 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.AreaId, Group = groups[area.BuildingId] }; model.PullAreaList = (from area in allAreas where area.AreaType == BucketActivityType.Pulling select new SelectListItem { Text = string.Format("{0}: {1} ({2:N0}% SKUs available)", area.ShortName, area.Description, area.PctSkuAvailable), Value = area.AreaId, Selected = area.AreaId == model.PullAreaId, Group = area.Group }).ToList(); model.PitchAreaList = (from area in allAreas where area.AreaType == BucketActivityType.Pitching select new SelectListItem { Text = string.Format("{0}: {1} ({2:N0}% SKUs assigned.)", area.ShortName ?? area.AreaId, area.Description, area.PctSkuAvailable), Value = area.AreaId, Selected = area.AreaId == model.PitchAreaId, Group = area.Group }).ToList(); // Show only those areas which have some SKUs available //model.PullAreaList = (from area in bucketAreas // where area.AreaType == BucketActivityType.Pulling && area.CountOrderedSku.HasValue && area.CountOrderedSku.Value > 0 && // area.CountSku.HasValue && area.CountSku > 0 // orderby area.CountSku descending // let pctSkuAvailable = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value // 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.AreaId, // Selected = area.AreaId == model.PullAreaId, // Group = groups[area.BuildingId] // }).ToList(); //model.PitchAreaList = (from area in bucketAreas // where area.AreaType == BucketActivityType.Pitching && area.CountOrderedSku.HasValue && area.CountOrderedSku.Value > 0 && // area.CountSku.HasValue && area.CountSku > 0 // orderby area.CountSku descending // let pctSkuAssigned = area.CountSku.Value * 100.0 / (double)area.CountOrderedSku.Value // select new SelectListItem // { // Text = string.Format("{0}: {1} ({2:N0}% SKUs assigned.)", area.ShortName ?? area.AreaId, area.Description, pctSkuAssigned), // Value = area.AreaId, // Selected = area.AreaId == model.PitchAreaId // }).ToList(); model.CustomerName = _service.Value.GetCustomerName(model.CustomerId); }