public ActionResult CreateOrUpdateResource(string id, AppResourceViewModel model) { using (var context = new AppSecurityContext()) { try { var resource = mapper.Map <AppResource>(model); var repository = new ResourceRepository(context); if (id != null) { repository.Update(resource); } else { repository.Insert(resource); } context.SaveChanges(); return(RedirectToAction("Resources")); } catch (Exception ex) { ViewBag.Error = ex.Message; return(View(model)); } } }
public async Task <IHttpActionResult> GetApplicationResource(string id) { db = Request.GetOwinContext().Get <SecurityDbContext>(); ApplicationResource applicationResource = await db.Resources.FindAsync(id); if (applicationResource == null) { return(NotFound()); } var appResourceViewModel = new AppResourceViewModel(applicationResource); return(Ok(appResourceViewModel)); }
public ActionResult CreateOrUpdateResource(string id) { var model = new AppResourceViewModel(); if (id != null) { using (var context = new AppSecurityContext()) { var repository = new ResourceRepository(context); var resource = repository.Find(id); model = mapper.Map <AppResourceViewModel>(resource); return(View(model)); } } return(View(model)); }