public ActionResult Create(SymbolPackage symbolPackage) { ViewBag.IsAdmin = false; if (Request.IsAuthenticated) { ViewBag.IsAdmin = _authorizationService.IsAdmin(); } if (!ViewBag.IsAdmin) { return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized)); } ViewBag.Themes = new SelectList(CodeList.Themes(), "Key", "Value", symbolPackage.Theme); if (ModelState.IsValid) { try { _symbolService.AddPackage(symbolPackage); return(RedirectToAction("Index")); } catch (Exception ex) { Log.Error(ex); ModelState.AddModelError("error", ex.Message); } } return(View(symbolPackage)); }
public HttpResponseMessage PostPackage(SymbolPackage package) { try { return(Request.CreateResponse(HttpStatusCode.OK, _symbolService.AddPackage(package))); } catch (PackageException pex) { Log.Error("Error API", pex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new HttpError(pex.Message))); } catch (Exception ex) { Log.Error("Error API", ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, new HttpError("Kunne ikke legge til pakke"))); } }