Ejemplo n.º 1
0
 public ActionResult Create(ResourceDocViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var resource = _resourceRepository.GetById(viewModel.ResourceId);
             var resourceDoc = new ResourceDoc()
                                   {
                                       Resource = resource
                                   };
             viewModel.MapOntoModel(ref resourceDoc);
             _resourceDocRepository.Add(resourceDoc);
             _resourceDocRepository.SaveChanges(); 
             return RedirectToAction("Details", "Resources", new { id = resource.Id });
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", ex.Message);
         }
     }
     return View(viewModel);
 }
Ejemplo n.º 2
0
        public ActionResult Edit(ResourceDocViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var resourceDoc = _resourceDocRepository.GetById(viewModel.Id);
                    if (resourceDoc == null) throw new HttpException(404, "");

                    viewModel.MapOntoModel(ref resourceDoc);
                    _resourceDocRepository.Save(resourceDoc);
                    _resourceDocRepository.SaveChanges();

                    return RedirectToAction("Details", "Resources", new {id = resourceDoc.Resource.Id});
                }
                catch (HttpException)
                {
                    throw;
                }
                catch (Exception exception)
                {
                    ModelState.AddModelError("", exception);
                }
            }
            return View(viewModel);
        }