public ActionResult Create(int id) { IEnumerable<Company> companies = Company.GetAllCompany(); IEnumerable<BinderType> bindersType = BinderType.GetAllBinderTypes(); Company company = Company.GetCompanyById(id); if (company == null) { return HttpNotFound(); } var model = new BinderViewModel(); model.CompanyName = company.CompanyName; model.CompanyId = id; model.BinderTypes = new List<BinderTypeViewModel>(); foreach (var binderType in bindersType) { var binderTypeViewModel = new BinderTypeViewModel { BinderTypeId = binderType.BinderTypeId, BinderTypeName = binderType.BinderTypeName, IsSelected = false }; model.BinderTypes.Add(binderTypeViewModel); } return View(model); }
public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } Binder binder = Binder.GetBinderById(id); var model = new BinderViewModel { BarCode = binder.BarCode, BinderId = binder.BinderId, CompanyId = binder.CompanyId, CompanyName = GlobalVariables.CompanyName, Description = binder.Description, Location = binder.Location, Year = binder.Year }; var binderTypes = BinderType.GetAllBinderTypes(); var binderTypeBinders = BinderTypeBinder.GetBinderTypeBindersById(id); foreach (var binderType in binderTypes) { BinderTypeViewModel btvm = new BinderTypeViewModel { BinderTypeId = binderType.BinderTypeId, BinderTypeName = binderType.BinderTypeName, }; foreach (var binderTypeBinder in binderTypeBinders) { if (binderType.BinderTypeId == binderTypeBinder.BynderTypeId) { btvm.IsSelected = binderTypeBinder.IsType; } } model.BinderTypes.Add(btvm); } ViewBag.CompanyName = GlobalVariables.CompanyName; if (binder == null) { return HttpNotFound(); } return View(model); }