public ActionResult Update(string id) { if (this.IsValidId(id)) { if (id.HasTrailingForwardSlash()) { id = id.RemoveTrailingForwardSlash(); } var applet = this.AmiClient.GetApplet(id); if (applet == null) { TempData["error"] = Locale.AppletNotFound; return(RedirectToAction("Index")); } var model = new UploadAppletModel { AppletViewModel = new AppletViewModel(applet), Id = id }; return(View(model)); } TempData["error"] = Locale.AppletNotFound; return(RedirectToAction("Index")); }
public ActionResult Upload(UploadAppletModel model) { try { if (ModelState.IsValid) { var fileInfo = new FileInfo(model.File.FileName); switch (fileInfo.Extension) { case ".pak": try { AppletPackage package; using (var stream = new GZipStream(model.File.InputStream, CompressionMode.Decompress)) { var serializer = new XmlSerializer(typeof(AppletPackage)); package = (AppletPackage)serializer.Deserialize(stream); } this.AmiClient.CreateApplet(package); TempData["success"] = Locale.AppletUploadedSuccessfully; return(RedirectToAction("Index")); } catch (Exception e) { Trace.TraceError($"Unable to upload applet: {e}"); ModelState.AddModelError(nameof(model.File), Locale.UnableToUploadApplet); } break; default: ModelState.AddModelError(nameof(model.File), Locale.UnableToUploadApplet); break; } } } catch (Exception e) { Trace.TraceError($"Unable to upload applet: {e}"); } TempData["error"] = Locale.UnableToUploadApplet; return(View(model)); }
public ActionResult Update(UploadAppletModel model) { AppletPackage package = null; try { if (ModelState.IsValid) { var fileInfo = new FileInfo(model.File.FileName); switch (fileInfo.Extension) { case ".pak": try { using (var stream = new GZipStream(model.File.InputStream, CompressionMode.Decompress)) { var serializer = new XmlSerializer(typeof(AppletPackage)); package = (AppletPackage)serializer.Deserialize(stream); } } catch (Exception e) { Trace.TraceError($"Unable to decode applet: {e}"); ModelState.AddModelError(nameof(model.File), Locale.UnableToUploadApplet); } break; default: ModelState.AddModelError(nameof(model.File), Locale.UnableToUploadApplet); break; } // ensure that the model state wasn't invalidated when attempting to serialize the applet file if (ModelState.IsValid) { this.AmiClient.UpdateApplet(package.Meta.Id, package); TempData["success"] = Locale.AppletUploadedSuccessfully; return(RedirectToAction("Index")); } } } catch (Exception e) { Trace.TraceError($"Unable to update applet: {e}"); } if (model.Id.HasTrailingForwardSlash()) { model.Id = model.Id.RemoveTrailingForwardSlash(); } var applet = this.AmiClient.GetApplet(model.Id); if (applet == null) { TempData["error"] = Locale.AppletNotFound; return(RedirectToAction("Index")); } model.AppletViewModel = new AppletViewModel(applet); TempData["error"] = Locale.UnableToUploadApplet; return(View(model)); }