public ActionResult Create(ResourceViewModel viewModel) { try { if (ModelState.IsValid) { var model = new Resource(); viewModel.MapOntoModel(ref model); var newDoc = new ResourceDoc(); viewModel.NewDoc.MapOntoModel(ref newDoc); model.ResourceDocs.Add(newDoc); _resourceRepository.Add(model); _resourceRepository.SaveChanges(); return RedirectToAction("Index"); } else { return View(viewModel); } } catch(Exception ex) { _logger.Error("ResourcesController.Create", ex); ModelState.AddModelError("", ex); return View(viewModel); } }
public ActionResult Create() { var viewModel = new ResourceViewModel(); return View(viewModel); }
public ActionResult CreateField(ResourceViewModel viewModel) { //if (ModelState.IsValid) //{ var resource = _resourceRepository.GetById(viewModel.Id); var field = new Field() { Resource = resource, Name = viewModel.NewField.Name, FieldType = viewModel.NewField.FieldType }; field.FieldDocs.Add(new FieldDoc() { Language = Configuration.DefaultLanguage, Description = viewModel.NewField.Description, Field = field }); resource.Fields.Add(field); _resourceRepository.Save(resource); _resourceRepository.SaveChanges(); return RedirectToAction("Edit", new { id = viewModel.Id }); //} //else //{ // return View("Edit", viewModel); //} }
public ActionResult CreateResourceDoc(ResourceViewModel viewModel) { //if (ModelState.IsValid) //{ var resource = _resourceRepository.GetById(viewModel.Id); var doc = new ResourceDoc() { Resource = resource }; viewModel.NewDoc.MapOntoModel(ref doc); resource.ResourceDocs.Add(doc); _resourceRepository.SaveChanges(); return RedirectToAction("Edit", new { id = viewModel.Id }); //} //else //{ // return View("Edit", viewModel); //} }
public ActionResult Delete(ResourceViewModel viewModel) { try { _resourceRepository.DeleteById(viewModel.Id); _resourceRepository.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(ResourceViewModel viewModel) { try { if (ModelState.IsValid) { var resource = _resourceRepository.GetById(viewModel.Id); viewModel.MapOntoModel(ref resource); _resourceRepository.Save(resource); _resourceRepository.SaveChanges(); return RedirectToAction("Index"); } else { return View(viewModel); } } catch { return View(); } }