void SaveState(AirlineGroupViewModel model) { //create comma delimited list of product ids model.SavedRequested = string.Join(",", model.RequestedAirline.Select(p => p.AirlineId.ToString()).ToArray()); model.AvailableAirline = cacheRepository.GetCacheAirlines().Except(model.RequestedAirline).ToList(); }
public ActionResult Create(AirlineGroupViewModel model, string add, string remove, string send) { //Need to clear model state or it will interfere with the updated model ModelState.Clear(); RestoreSavedState(model); if (!string.IsNullOrEmpty(add)) { AddAirlines(model); } else if (!string.IsNullOrEmpty(remove)) { RemoveAirlines(model); } else if (!string.IsNullOrEmpty(send)) { Validate(model); if (ModelState.IsValid) { ///// Collecting all airline id string[] SavedGroupAirline = GetStringArray(model.SavedRequested); ///// Collecting last saved id _airgrouprepo.SaveAirlineGroup(model); int Groupid = _airgrouprepo.GetLastId().ToList().Last().AirlineGroupId; //////// Saving all list of Acces airline id int[] AllSavedId = SavedGroupAirline.Select(x => int.Parse(x)).ToArray(); _airgrouprepo.CollectMappingInfo(AllSavedId, Groupid); return(RedirectToAction("Index")); } //Todo: Repository.ClearCache();... } SaveState(model); return(View(model)); }
void RemoveAirlines(AirlineGroupViewModel model) { if (model.RequestedSelected != null) { model.RequestedAirline.RemoveAll(p => model.RequestedSelected.Contains(p.AirlineId)); model.RequestedSelected = null; } }
void AddAirlines(AirlineGroupViewModel model) { if (model.AvailableSelected != null) { var airline = cacheRepository.GetCacheAirlines().Where(p => model.AvailableSelected.Contains(p.AirlineId)); model.RequestedAirline.AddRange(airline); model.AvailableSelected = null; } }
// // GET: /AirlineGroup/Create public ActionResult Create() { AirlineGroupViewModel model = new AirlineGroupViewModel { AvailableAirline = cacheRepository.GetCacheAirlines().ToList(), RequestedAirline = new List <Airlines>() }; return(View(model)); }
public void SaveAirlineGroup(AirlineGroupViewModel model) { var entitymodel = new AirlineGroups { AirlineGroupName = model.GroupName, }; ent.AddToAirlineGroups(entitymodel); ent.SaveChanges(); }
void RestoreSavedState(AirlineGroupViewModel model) { model.RequestedAirline = new List <Airlines>(); //get the previously stored items if (!string.IsNullOrEmpty(model.SavedRequested)) { string[] Airlineids = model.SavedRequested.Split(','); var airlines = cacheRepository.GetCacheAirlines().Where(p => Airlineids.Contains(p.AirlineId.ToString())); model.RequestedAirline.AddRange(airlines); } }
// // GET: /AirlineGroup/Edit/5 public ActionResult Edit(int id) { AirlineGroupViewModel model = new AirlineGroupViewModel { AvailableAirline = cacheRepository.GetCacheAirlines().ToList(), RequestedAirline = _airgrouprepo.GetAllAddedAirlineGroupListForEdit(id), GroupName = _airgrouprepo.GetAirlineGroupName(id) }; return(View(model)); }
private void Validate(AirlineGroupViewModel model) { //if (model.RequestedTotal > 400m) // ModelState.AddModelError("", "Total must be 400 or less"); if (string.IsNullOrEmpty(model.GroupName)) { ModelState.AddModelError("GroupName", "Please Enter Group Name"); } if (string.IsNullOrEmpty(model.SavedRequested)) { ModelState.AddModelError("", "You haven't selected any presents!"); } }