/// <summary> /// This is a private method which populates various list of areas acoording to passed flags. /// </summary> /// <param name="model"></param> private void PopulateIndexViewModel(ProcessEditorViewModel model) { var areas = _service.Value.GetCartonAreas().ToList(); if (areas.Any(p => p.IsReceivingArea)) { model.ReceivingAreasList = areas.Where(p => !p.IsNumberedArea && p.IsReceivingArea).Select(p => Map(p)).ToArray(); } else { model.ReceivingAreasList = areas.Where(p => !p.IsNumberedArea).Select(p => Map(p)).ToArray(); } if (areas.Any(p => p.IsSpotCheckArea)) { model.SpotCheckAreasList = areas.Where(p => !p.IsNumberedArea && p.IsSpotCheckArea).Select(p => Map(p)).ToArray(); } else { model.SpotCheckAreasList = areas.Where(p => !p.IsNumberedArea).Select(p => Map(p)).ToArray(); } model.PriceSeasonCodeList = _service.Value.GetPriceSeasonCodes().Select(p => new SelectListItem { Text = p.Item1 + ":" + p.Item2, Value = p.Item1 }); }
public virtual ActionResult CreateProcess(int?processId) { var model = new ProcessEditorViewModel(); if (processId != null) { // Getting process info for editing case var src = _service.Value.GetProcessInfo(processId.Value); model = new ProcessEditorViewModel { ProDate = src.ProDate, ProNumber = src.ProNumber, CarrierId = src.CarrierId, CarrierDisplayName = string.Format("{0}: {1}", src.CarrierId, src.CarrierName), PalletCount = src.PalletCount, ReceivingAreaId = src.ReceivingAreaId, ProcessId = src.ProcessId, ExpectedCartons = src.ExpectedCartons, PalletLimit = src.PalletLimit, PriceSeasonCode = src.PriceSeasonCode, SpotCheckAreaId = src.SpotCheckAreaId }; model.ProcessId = src.ProcessId; } else { if (Request.Cookies[COOKIE_ALERT] != null) { model.ReceivingAreaId = Request.Cookies[COOKIE_ALERT][COOKIE_ALERT_RECEIVING_AREA]; model.SpotCheckAreaId = Request.Cookies[COOKIE_ALERT][COOKIE_ALERT_SPOT_CHECK_AREA]; model.PriceSeasonCode = Request.Cookies[COOKIE_ALERT][KEY_PRICE_SEASON_CODE]; if (!string.IsNullOrEmpty(Request.Cookies[COOKIE_ALERT][KEY_PALLET_LIMIT])) { model.PalletLimit = Convert.ToInt32(Request.Cookies[COOKIE_ALERT][KEY_PALLET_LIMIT]); } } } PopulateIndexViewModel(model); return(View(Views.ProcessEditor, model)); }
public virtual ActionResult CreateUpdateProcess(ProcessEditorViewModel model) { if (!ModelState.IsValid) { PopulateIndexViewModel(model); return(View(Views.ProcessEditor, model)); } var carrier = _service.Value.GetCarrier(model.CarrierId); if (carrier == null) { ModelState.AddModelError("", string.Format("{0} is invalid Carrier", model.CarrierId)); PopulateIndexViewModel(model); return(View(Views.ProcessEditor, model)); } var processModel = new ReceivingProcess { ProDate = model.ProDate, ProNumber = model.ProNumber, CarrierId = model.CarrierId, ReceivingAreaId = model.ReceivingAreaId, SpotCheckAreaId = model.SpotCheckAreaId, PalletLimit = model.PalletLimit, //CartonCount = model.CartonCount, ExpectedCartons = model.ExpectedCartons ?? 0, PalletCount = model.PalletCount, ProcessId = model.ProcessId ?? 0, PriceSeasonCode = model.PriceSeasonCode }; var cookie = new HttpCookie(COOKIE_ALERT); if (model.ProcessId == null) { //Creating New Process try { _service.Value.InsertProcess(processModel); //Adding the values to cookie if (!string.IsNullOrEmpty(model.ReceivingAreaId) || !string.IsNullOrEmpty(model.SpotCheckAreaId) || !string.IsNullOrEmpty(model.PriceSeasonCode) || model.PalletLimit != null) { cookie.Values.Add(COOKIE_ALERT_RECEIVING_AREA, model.ReceivingAreaId); cookie.Values.Add(COOKIE_ALERT_SPOT_CHECK_AREA, model.SpotCheckAreaId); cookie.Values.Add(KEY_PRICE_SEASON_CODE, model.PriceSeasonCode); cookie.Values.Add(KEY_PALLET_LIMIT, model.PalletLimit.ToString()); cookie.Expires = DateTime.Now.AddDays(15); this.HttpContext.Response.Cookies.Add(cookie); } } catch (ProviderException ex) { // Exception happened but we still need to populate all the area lists. PopulateIndexViewModel(model); ModelState.AddModelError("", ex.Message); return(View(Views.ProcessEditor, model)); } } else { //updating existing Process try { _service.Value.UpdateProcess(processModel); } catch (ProviderException ex) { // Exception happened but we still need to populate all the area lists. PopulateIndexViewModel(model); ModelState.AddModelError("", ex.Message); return(View(Views.ProcessEditor, model)); } } return(RedirectToAction(MVC_Receiving.Receiving.Home.Receiving(processModel.ProcessId))); }