public ActionResult Edit(Brand brand, string @return) { JsonResultData resultEntry = new JsonResultData(ModelState); try { if (ModelState.IsValid) { if (this.Request.Files.Count > 0) { brand.LogoFile = new EntityFile(); brand.LogoFile.FileName = this.Request.Files[0].FileName; brand.LogoFile.Data = this.Request.Files[0].InputStream; brand.LogoFile.CommerceName = AppSetting.CurrentCommerce; } brand.UtcUpdateDateTime = DateTime.UtcNow; this._brandService.Update(brand); resultEntry.RedirectUrl = @return; } } catch (Exception ex) { resultEntry.AddException(ex); } return(Json(resultEntry)); }
public virtual ActionResult ImageDetailInfo(string fileUrl) { var filePath = Server.MapPath(System.Web.HttpUtility.UrlDecode(fileUrl)); JsonResultData jsonData = new JsonResultData(); try { using (var img = System.Drawing.Image.FromFile(filePath)) { jsonData.Model = new { Width = img.Width, Height = img.Height }; } } catch (Exception e) { jsonData.AddException(e); } // ret return(Json(jsonData)); }
public virtual ActionResult Publish(string siteName) { if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentNullException("siteName"); } var site = SiteHelper.Parse(siteName); if (site == null) { throw new NullReferenceException("site"); } site = site.AsActual(); var rootSite = SiteHelper.GetRootSite(site).AsActual(); if (string.IsNullOrWhiteSpace(rootSite.ClientId)) { throw new Exception("Customer ID is not specified".Localize()); } var ip = rootSite.FrontendDefaultIp; var path = Path.Combine(site.PhysicalPath, rootSite.FrontendPhysicalPath); var protocol = rootSite.FrontendDefaultProtocol; var port = rootSite.FrontendDefaultPort; var appPoolName = rootSite.FrontendDefaultApplicationPoolName; var name = site.UID; //string.Format("Frontend.{0}.{1}", rootSite.ClientId, siteName); //Chek domain name // if (site.Domains == null || site.Domains.Length == 0) { var result = new JsonResultData(ModelState); result.AddErrorMessage("Before publish site you must specify the domain name (System/Settings/Domain/Domains)".Localize()); return(Json(result)); } try { //Create web site // IISHelper.CreateWebSite(appPoolName, name, protocol, ip, site.Domains.ToArray(), port, path); } catch (Exception e) { var result = new JsonResultData(); result.AddException(new Exception("Fail to publication.".Localize() + " " + e.Message, e)); return(Json(result)); } //Result // var data = new JsonResultData(ModelState); data.ReloadPage = true; return(Json(data)); }
protected override void OnException(ExceptionContext filterContext) { base.OnException(filterContext); if (filterContext.HttpContext.Request.IsAjaxRequest()) { var result = new JsonResultData(); result.AddException(filterContext.Exception); filterContext.Result = Json(result, JsonRequestBehavior.AllowGet); filterContext.ExceptionHandled = true; } }
public static ActionResult ReturnActionResult(ControllerContext controllerContext, object model, Exception exception) { var jsonResult = controllerContext.RequestContext.GetRequestValue("JsonResult"); string redirectUrl = ""; if (exception == null) { redirectUrl = controllerContext.RequestContext.GetRequestValue("SuccessedUrl"); } else { controllerContext.HttpContext.Session["Exception"] = exception; redirectUrl = controllerContext.RequestContext.GetRequestValue("FailedUrl"); } if (jsonResult.EqualsOrNullEmpty("true", StringComparison.OrdinalIgnoreCase)) { var data = new JsonResultData() { Model = model, RedirectUrl = redirectUrl }; if (exception != null) { data.AddException(exception); if ((exception is RuleViolationException)) { ((RuleViolationException)exception).FillIssues(controllerContext.Controller.ViewData.ModelState); data.AddModelState(controllerContext.Controller.ViewData.ModelState); } } return(new JsonResult() { Data = data }); } if (exception != null && string.IsNullOrEmpty(redirectUrl)) { throw exception; } if (!string.IsNullOrEmpty(redirectUrl)) { return(new RedirectResult(redirectUrl)); } if (controllerContext.HttpContext.Request.UrlReferrer != null) { return(new RedirectResult(controllerContext.HttpContext.Request.UrlReferrer.OriginalString)); } return(new EmptyResult()); }
public ActionResult Delete(DeleteInfo[] model) { JsonResultData resultEntry = new JsonResultData(ModelState); try { this._brandService.Delete(model.Select(it => it.Id).ToArray()); resultEntry.RedirectUrl = Url.Action("Index", ControllerContext.RequestContext.AllRouteValues().Merge("id", null)); } catch (Exception ex) { resultEntry.AddException(ex); } return(Json(resultEntry)); }
public ActionResult Delete(string commerceName, string @return) { JsonResultData resultEntry = new JsonResultData(ModelState); try { this._commerceService.Delete(commerceName); } catch (Exception ex) { resultEntry.AddException(ex); } return(Json(resultEntry)); }
public virtual ActionResult Edit(string folderName, string uuid, FormCollection form, string @return, bool localize = false) { var data = new JsonResultData(); try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; TextContent previous = Session["EditableObject"] as TextContent; TextContentManager.Update(Repository, textFolder, uuid, form, Request.Files, DateTime.UtcNow, addedCategories, removedCategories, User.Identity.Name, previous: previous); if (localize == true) { TextContentManager.Localize(textFolder, uuid); } data.RedirectToOpener = true; data.RedirectUrl = @return; } } catch (RuleViolationException violationException) { foreach (var item in violationException.Issues) { ModelState.AddModelError(item.PropertyName, item.ErrorMessage); } data.Success = false; } catch (Exception e) { data.AddException(e); } data.AddModelState(ModelState); return(Json(data)); }
public ActionResult Create(CommerceSetting setting, string @return) { JsonResultData resultEntry = new JsonResultData(ModelState); try { if (ModelState.IsValid) { this._commerceService.Add(setting); resultEntry.RedirectUrl = Url.Action("Index", "Brand", new { CommerceName = setting.Name }); } } catch (Exception ex) { resultEntry.AddException(ex); } return(Json(resultEntry)); }
public ActionResult Delete(News[] model) { JsonResultData resultEntry = new JsonResultData(); try { foreach (var item in model) { repository.Delete(item); } resultEntry.RedirectUrl = Url.Action("Index", ControllerContext.RequestContext.AllRouteValues().Merge("id", null)); } catch (Exception e) { resultEntry.AddException(e); } return(Json(resultEntry)); }
public virtual ActionResult Import(bool @override, string @return) { JsonResultData resultEntry = new JsonResultData(ModelState); try { if (Request.Files.Count > 0 && Request.Files[0].ContentLength > 0) { Manager.Import(Site, Request.Files[0].InputStream, @override); } resultEntry.RedirectUrl = @return; } catch (Exception e) { resultEntry.AddException(e); } return(Json(resultEntry, "text/plain", System.Text.Encoding.UTF8)); }
public ActionResult Index(string siteName, ModuleInfo_Metadata moduleInfo) { JsonResultData resultEntry = new JsonResultData(ModelState); try { if (ModelState.IsValid) { ModuleInfo.SaveModuleSetting(ModuleName, siteName, moduleInfo.Settings); resultEntry.AddMessage("Module setting has been changed.".Localize()); } } catch (Exception e) { resultEntry.AddException(e); } return(Json(resultEntry)); }
public ActionResult Edit(int id, News news, string @return) { JsonResultData resultEntry = new JsonResultData(ViewData.ModelState); try { if (ModelState.IsValid) { repository.Update(news); resultEntry.RedirectUrl = @return; } } catch (Exception e) { resultEntry.AddException(e); } return(Json(resultEntry)); }
public virtual ActionResult Create(string folderName, string parentFolder, string parentUUID, FormCollection form, string @return) { var data = new JsonResultData(); try { if (ModelState.IsValid) { TextFolder textFolder = new TextFolder(Repository, folderName).AsActual(); var schema = textFolder.GetSchema().AsActual(); SchemaPath schemaPath = new SchemaPath(schema); IEnumerable <TextContent> addedCategories; IEnumerable <TextContent> removedCategories; ParseCategories(form, out addedCategories, out removedCategories); ContentBase content; content = TextContentManager.Add(Repository, textFolder, parentFolder, parentUUID, form, Request.Files, addedCategories, User.Identity.Name); data.RedirectUrl = @return; } } catch (RuleViolationException ruleEx) { foreach (var item in ruleEx.Issues) { data.AddFieldError(item.PropertyName, item.ErrorMessage); } } catch (Exception e) { data.AddException(e); } data.AddModelState(ModelState); return(Json(data)); }
public virtual ActionResult ChangeSiteState(string siteName, string state) { try { if (string.IsNullOrWhiteSpace(siteName)) { throw new ArgumentNullException("siteName"); } if (string.IsNullOrWhiteSpace(state)) { throw new ArgumentNullException("state"); } var site = SiteHelper.Parse(siteName); if (site == null) { throw new NullReferenceException("site"); } site = site.AsActual(); IISHelper.SiteState(site.UID, (StateOperationSite)Enum.Parse(typeof(StateOperationSite), state)); } catch (Exception e) { var result = new JsonResultData(); result.AddException(new Exception("Fail change site state.".Localize() + " " + e.Message, e)); return(Json(result)); } //Result // var data = new JsonResultData(ModelState); data.ReloadPage = true; return(Json(data)); }
public System.Web.Mvc.ActionResult Submit(Site site, ControllerContext controllerContext, SubmissionSetting submissionSetting) { // Setup temp fields Site = site; ControllerContext = controllerContext; SubmissionSetting = submissionSetting; var model = new TModel(); if (!ModelBindHelper.BindModel <TModel>(model, "", ControllerContext, SubmissionSetting)) { var resultData = new JsonResultData(); resultData.Success = false; resultData.AddModelState(ControllerContext.Controller.ViewData.ModelState); ClearTempFields(); return(new JsonResult { Data = resultData }); } try { var result = Execute(model); string redirectUrl = null; if (result != null) { redirectUrl = result.RedirectUrl; } if (!String.IsNullOrEmpty(redirectUrl)) { return(RedirectTo(redirectUrl, result == null ? null : result.Data)); } else { return(new JsonResult { Data = new JsonResultData { Success = true, Model = result == null ? null : result.Data } }); } } catch (InvalidModelStateException ex) { var resultData = new JsonResultData(); resultData.Success = false; resultData.AddModelState(ex.ModelState); return(new JsonResult { Data = resultData }); } catch (Exception ex) { Kooboo.HealthMonitoring.Log.LogException(ex); var resultData = new JsonResultData(); resultData.Success = false; resultData.AddException(ex); return(new JsonResult { Data = resultData }); } finally { ClearTempFields(); } }
public virtual ActionResult EditImage(string folderName, string uuid, [System.Web.Mvc.Bind(Prefix = "Crop")] ImageCropModel cropModel, [System.Web.Mvc.Bind(Prefix = "Scale")] ImageScaleModel scaleModel, string rotateTypes, string @return) { var mediaFolder = FolderHelper.Parse <MediaFolder>(Repository.Current, folderName); var mediaContent = mediaFolder.CreateQuery().WhereEquals("UUID", uuid).FirstOrDefault(); JsonResultData data = new JsonResultData(ModelState); Stream targetStream = new MemoryStream(); MemoryStream resizedImage = new MemoryStream(); Stream imageStream = new MemoryStream(); int width = 0, height = 0; try { ImageFormat imageFormat = ImageTools.ConvertToImageFormat(Path.GetExtension(mediaContent.PhysicalPath)); imageStream = RotateImage(rotateTypes, mediaContent.PhysicalPath, imageFormat); if (cropModel != null && cropModel.X.HasValue && cropModel.Width.Value > 0 && cropModel.Height.Value > 0) { ImageTools.CropImage(imageStream, targetStream, imageFormat, cropModel.X.Value, cropModel.Y.Value, cropModel.Width.Value, cropModel.Height.Value); targetStream.Position = 0; } else { targetStream = imageStream; } if (scaleModel != null && scaleModel.Height.HasValue && scaleModel.Width.HasValue) { ImageTools.ResizeImage(targetStream, resizedImage, imageFormat, scaleModel.Width.Value, scaleModel.Height.Value, scaleModel.PreserveAspectRatio, scaleModel.Quality ?? 80); resizedImage.Position = 0; targetStream = resizedImage; } Image image = Image.FromStream(targetStream); width = image.Width; height = image.Height; targetStream.Position = 0; ServiceFactory.MediaContentManager.Update(Repository.Current, mediaFolder, uuid, mediaContent.FileName, targetStream, User.Identity.Name); image.Dispose(); targetStream.Close(); //data.ClosePopup = true; //data.AddMessage("The image has been changed.".Localize()); } catch (Exception e) { data.AddException(e); } finally { if (targetStream != null) { targetStream.Close(); targetStream.Dispose(); targetStream = null; } if (resizedImage != null) { resizedImage.Close(); resizedImage.Dispose(); resizedImage = null; } if (imageStream != null) { imageStream.Close(); imageStream.Dispose(); imageStream = null; } } data.Model = new { Width = width, Height = height }; data.RedirectToOpener = false; data.ReloadPage = true; return(Json(data)); }