bool ISoftwareType.Insert(SoftwareTypeViewModel model) { using (var ent = new CustomerSupportEntities()) { var newRow = new tblSoftwareType(); newRow.SoftwareTypeName = model.SoftwareTypeName; ent.tblSoftwareTypes.Add(newRow); int success = ent.SaveChanges(); if (success > 0) { return(true); } else { return(false); } } }
public IActionResult EditType(SoftwareTypeViewModel vm) { SoftwareType model = new SoftwareType() { ID = vm.ID, Description = vm.Description, Name = vm.Name, }; _db.SoftwareTypes.Update(model); _db.SaveChanges(); int counter = 0; List <SoftwareTypeOptions> softwareTypeOptions = new List <SoftwareTypeOptions>(); foreach (var option in vm.hiddenID) { SoftwareTypeOptions softwareTypeOption = new SoftwareTypeOptions() { SoftwareOptionID = Convert.ToInt32(option), SoftwareTypeID = model.ID, Value = vm.Values[counter].ToString(), }; //_db.Update(softwareTypeOption); softwareTypeOptions.Add(softwareTypeOption); counter++; } var type = _db.SoftwareTypes.Include(c => c.SoftwareTypeOptions).FirstOrDefault(x => x.ID == vm.ID); type.SoftwareTypeOptions.Clear(); type.SoftwareTypeOptions = softwareTypeOptions; _db.Update(type); _db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult EditType(long id) { var model = _db.SoftwareTypes.Include(b => b.SoftwareTypeOptions).FirstOrDefault(x => x.ID == id); SoftwareTypeViewModel typeViewModel = new SoftwareTypeViewModel() { ID = model.ID, Description = model.Description, Name = model.Name, }; ViewBag.ListOfOption = _db.SoftwareOptions.ToList(); if (model.SoftwareTypeOptions != null) { typeViewModel.hiddenID = model.SoftwareTypeOptions.Select(b => b.SoftwareOptionID.ToString()).ToArray(); typeViewModel.Values = model.SoftwareTypeOptions.Select(c => c.Value).ToArray(); } return(View(typeViewModel)); }
public IActionResult CreateType(SoftwareTypeViewModel vm) { SoftwareType model = new SoftwareType() { Description = vm.Description, Name = vm.Name, }; _db.SoftwareTypes.Add(model); _db.SaveChanges(); int counter = 0; List <SoftwareTypeOptions> softwareTypeOptions = new List <SoftwareTypeOptions>(); foreach (var option in vm.hiddenID) { SoftwareTypeOptions softwareTypeOption = new SoftwareTypeOptions() { SoftwareOptionID = Convert.ToInt32(option), SoftwareTypeID = model.ID, Value = vm.Values[counter].ToString(), }; _db.Add(softwareTypeOption); counter++; } _db.SaveChanges(); return(RedirectToAction("Index", "Attribute")); //_db.Attribute.Add(attribute); //_db.SaveChanges(); //return RedirectToAction("Index"); //return View("Index"); }
public ActionResult Create(SoftwareTypeViewModel model) { SoftwareType.Insert(model); return(View("Index")); }