public ActionResult Create(ApplicationRoleViewModel applicationRoleViewModel) { if (ModelState.IsValid) { var newApplicationRole = new ApplicationRole(); newApplicationRole.UpdateApplicationRole(applicationRoleViewModel); _appRoleService.Add(newApplicationRole); _appRoleService.Save(); return(RedirectToAction("Index")); } return(View()); }
public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel) { if (ModelState.IsValid) { var newAppRole = new ApplicationRole(); newAppRole.UpdateApplicationRole(applicationRoleViewModel); try { _appRoleService.Add(newAppRole); try { _appRoleService.Save(); } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } throw; } return(request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel)); } catch (NameDuplicatedException dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel appRoleViewModel) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState); } else { ApplicationRole appRole = new ApplicationRole(); appRole.UpdateApplicationRole(appRoleViewModel, "create"); var result = _applicationRoleService.Add(appRole); _applicationRoleService.Save(); response = request.CreateResponse(HttpStatusCode.OK, result); } return response; })); }
public HttpResponseMessage Create(HttpRequestMessage request, ApplicationRoleViewModel applicationRoleViewModel) { if (ModelState.IsValid) { var newAppRole = new ApplicationRole(); newAppRole.UpdateApplicationRole(applicationRoleViewModel); try { _appRoleService.Add(newAppRole); _appRoleService.Save(); return(request.CreateResponse(HttpStatusCode.OK, applicationRoleViewModel)); } catch (NameDuplicatedException dex) { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, dex.Message)); } } else { return(request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }