public async Task <ActionResult> ListTrims(TrimParameters parameters) { ValidateTrimParameters(parameters, TrimParametersValidator.NoValidation); var filter = new TrimFilter() { FilterMessage = parameters.FilterMessage, CarLine = parameters.CarLine, ModelYear = parameters.ModelYear, Gateway = parameters.Gateway, Action = TrimAction.TrimLevels }; filter.InitialiseFromJson(parameters); var results = await TrimViewModel.GetModel(DataContext, filter); var jQueryResult = new JQueryDataTableResultModel(results); foreach (var result in results.Trims.CurrentPage) { jQueryResult.aaData.Add(result.ToJQueryDataTableResult()); } return(Json(jQueryResult)); }
public async Task <ActionResult> TrimPage(TrimParameters parameters) { var filter = new TrimFilter() { PageIndex = PageIndex, PageSize = PageSize }; return(View(await TrimViewModel.GetModel(DataContext, filter))); }
public async Task <ActionResult> ContextMenu(TrimParameters parameters) { ValidateTrimParameters(parameters, TrimParametersValidator.TrimIdentifier); var filter = TrimFilter.FromParameters(parameters); filter.Action = TrimAction.Trim; var derivativeView = await TrimViewModel.GetModel(DataContext, filter); return(PartialView("_ContextMenu", derivativeView)); }
public ActionResult Edit(TrimViewModel trim, HttpPostedFileBase img) { if (ModelState.IsValid) { var myTrim = db.Trims.Find(trim.TrimId); if (img != null) { var folder = Server.MapPath("~/Content/Fabrics/"); var imageUrl = Path.GetFileName(img.FileName); var filename = Path.Combine(folder, imageUrl); img.SaveAs(filename); myTrim.ImageUrl = imageUrl; } myTrim.Name = trim.Name; myTrim.Description = trim.Description; foreach (var item in db.Trim_Restrictions) { if (item.TrimId == trim.TrimId) { db.Entry(item).State = EntityState.Deleted; } } foreach (var item in trim.Restrictions) { if (item.Checked) { db.Trim_Restrictions.Add(new Trim_Restrictions() { TrimId = trim.TrimId, RestrictionsId = item.Id }); } } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(trim)); }
// GET: Trims/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Trim trim = db.Trims.Find(id); if (trim == null) { return(HttpNotFound()); } var Results = from b in db.Restrictions select new { b.Id, b.Name, Checked = ((from ab in db.Trim_Restrictions where (ab.TrimId == id) && (ab.RestrictionsId == b.Id) select ab).Count() > 0) }; var MyViewModel = new TrimViewModel(); MyViewModel.TrimId = id.Value; MyViewModel.Name = trim.Name; MyViewModel.ImageUrl = trim.ImageUrl; MyViewModel.Description = trim.Description; var MyCheckBoxList = new List <CheckBoxViewModel>(); foreach (var item in Results) { MyCheckBoxList.Add(new CheckBoxViewModel { Id = item.Id, Name = item.Name, Checked = item.Checked }); } MyViewModel.Restrictions = MyCheckBoxList; return(View(MyViewModel)); }
private async Task <TrimViewModel> GetModelFromParameters(TrimParameters parameters) { return(await TrimViewModel.GetModel(DataContext, TrimMappingFilter.FromParameters(parameters))); }