public JsonResult ChangeTheme(string id) { var result = new AjaxResult(AjaxStatus.Normal, _localize.Get("Switching Theme...")); try { Service.ChangeTheme(id); result.Message = _localize.Get("Theme have switched."); } catch (Exception e) { result.Status = AjaxStatus.Error; result.Message = string.Format(_localize.Get("Switch failed - [{0}]"), e.Message); } return(Json(result)); }
public JsonResult Copy(string widgetId) { _cookie.SetValue(Const.CopyWidgetCookie, widgetId, true, true); return(Json(new AjaxResult { Status = AjaxStatus.Normal, Message = _localize.Get("Copy success") })); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.Name == "SingleLine" && data.FieldValue.IsNotNullAndWhiteSpace() && data.FieldValue.Length > 200) { message = _localize.Get("{0} length should be less than {1}").FormatWith(field.DisplayName, 200); return(false); } else if (field.Name == "Paragraph" && data.FieldValue.IsNotNullAndWhiteSpace() && data.FieldValue.Length > 1000) { message = _localize.Get("{0} length should be less than {1}").FormatWith(field.DisplayName, 1000); return(false); } return(true); }
public void Revert(string ID, bool RetainLatest) { BeginTransaction(() => { var page = Get(ID); if (page.IsPublishedPage) { var refPage = Get(page.ReferencePageID); refPage.IsPublish = false; Update(refPage); page.Description = _localize.Get("Revert from version: {0:g}").FormatWith(page.PublishDate); page.PublishDate = DateTime.Now; Add(page); var widgets = _widgetService.GetByPageId(ID); widgets.Each(m => { var widgetService = _widgetActivator.Create(m); m = widgetService.GetWidget(m); m.PageID = page.ID; widgetService.IsNeedNotifyChange = false; widgetService.Publish(m); }); _widgetService.RemoveCache(page.ReferencePageID); if (!RetainLatest) {//清空当前的所有修改 _layoutHtmlService.Remove(m => m.PageId == page.ReferencePageID); _zoneService.Remove(m => m.PageId == page.ReferencePageID); _layoutHtmlService.GetByPage(page).Each(m => { _layoutHtmlService.Add(new LayoutHtml { LayoutId = m.LayoutId, Html = m.Html, PageId = page.ReferencePageID }); }); _zoneService.GetByPage(page).Each(m => { m.PageId = page.ReferencePageID; _zoneService.Add(m); }); _widgetService.GetByPageId(page.ReferencePageID).Each(m => { var widgetService = _widgetActivator.Create(m); widgetService.IsNeedNotifyChange = false; widgetService.DeleteWidget(m.ID); }); _widgetService.GetByPageId(ID).Each(m => { var widgetService = _widgetActivator.Create(m); m = widgetService.GetWidget(m); m.PageID = page.ReferencePageID; widgetService.IsNeedNotifyChange = false; widgetService.Publish(m); }); } _zoneService.RemoveCache(page.ReferencePageID); _layoutHtmlService.RemoveCache(page.ReferencePageID); } }); }
public async Task <ActionResult> Login(AdminSignViewModel model, string ReturnUrl) { if (ModelState.IsValid) { var user = _userService.Login(model.UserID, model.PassWord, UserType.Administrator, Request.HttpContext.Connection.RemoteIpAddress.ToString()); if (user != null) { user.AuthenticationType = DefaultAuthorizeAttribute.DefaultAuthenticationScheme; var identity = new ClaimsIdentity(user); identity.AddClaim(new Claim(ClaimTypes.Name, user.UserID)); await HttpContext.SignInAsync(DefaultAuthorizeAttribute.DefaultAuthenticationScheme, new ClaimsPrincipal(identity)); if (ReturnUrl.IsNullOrEmpty() || !Url.IsLocalUrl(ReturnUrl)) { return(RedirectToAction("Index", "Dashboard")); } return(Redirect(ReturnUrl)); } else { ModelState.AddModelError("PassWord", _localize.Get("登录失败,用户名密码不正确")); } } return(View(model)); }
public override ServiceResult <Rule> Add(Rule item) { item = Init(item); try { _ruleManager.IsTrue(item.RuleExpression, new RuleWorkContext { }); } catch { var result = new ServiceResult <Rule>(); result.RuleViolations.Add(new RuleViolation("Title", _localize.Get("There is an error value in the condition, save failed!"))); return(result); } return(base.Add(item)); }
public override ServiceResult <UserEntity> Add(UserEntity item) { if (item.UserID.IsNullOrEmpty() && item.Email.IsNotNullAndWhiteSpace()) { item.UserID = item.Email; } if (item.PassWordNew.IsNotNullAndWhiteSpace()) { item.PassWord = item.PassWordNew; } if (item.PassWord.IsNotNullAndWhiteSpace()) { item.PassWord = ProtectPassWord(item.PassWord); } if (!item.Status.HasValue) { item.Status = (int)RecordStatus.Active; } if (Get(item.UserID) != null) { throw new Exception(_localize.Get("{0} is already exists").FormatWith(item.UserID)); } if (item.Email.IsNotNullAndWhiteSpace() && Count(m => m.Email == item.Email && m.UserTypeCD == item.UserTypeCD) > 0) { throw new Exception(_localize.Get("{0} is already exists").FormatWith(item.Email)); } var result = base.Add(item); if (!result.HasViolation) { if (item.Roles != null) { item.Roles.Each(m => { m.UserID = item.UserID; if (m.ActionType == ActionType.Create) { DbContext.UserRoleRelation.Add(m); } }); } DbContext.SaveChanges(); } return(result); }
public override ServiceResult <ProductEntity> Add(ProductEntity item) { ServiceResult <ProductEntity> result = new ServiceResult <ProductEntity>(); if (item.Url.IsNotNullAndWhiteSpace()) { if (GetByUrl(item.Url) != null) { result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists"))); return(result); } } _eventManager.Trigger(Events.OnProductAdding, item); BeginTransaction(() => { result = base.Add(item); if (!result.HasViolation) { if (item.ProductTags != null) { _productTagService.BeginBulkSave(); foreach (var tag in item.ProductTags.Where(m => m.Selected)) { _productTagService.Add(new ProductTag { ProductId = item.ID, TagId = tag.ID }); } _productTagService.SaveChanges(); } if (item.ProductImages != null) { item.ProductImages.Each(m => { m.ProductId = item.ID; if (m.ActionType == ActionType.Create) { _productImageService.Add(m); } }); } } }); _eventManager.Trigger(Events.OnProductAdded, item); return(result); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.Name == "Email" && data.FieldValue.IsNotNullAndWhiteSpace() && !Regex.IsMatch(data.FieldValue, RegularExpression.Email)) { message = _localize.Get("Invalid Email for {0}.").FormatWith(field.DisplayName); return(false); } return(true); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.IsRequired && data.FieldValue.IsNullOrWhiteSpace() && data.OptionValue.IsNullOrWhiteSpace()) { message = field.RequiredMessage ?? _localize.Get("{0}是必填的").FormatWith(field.DisplayName); return(false); } return(true); }
public IActionResult Submit(string FormId) { var result = Service.SaveForm(Request.Form, FormId); ModelState.Merge(result); if (!result.HasViolation) { TempData["Message"] = _localize.Get("Form have submited"); } return(View(result.Result.Form)); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; decimal result; if (field.Name == "Number" && data.FieldValue.IsNotNullAndWhiteSpace() && !Decimal.TryParse(data.FieldValue, out result)) { message = _localize.Get("Invalid Number for {0}.").FormatWith(field.DisplayName); return(false); } return(true); }
public JsonResult GetSelectNavTree() { var navs = Service.Get().OrderBy(m => m.DisplayOrder).ToList(); var node = new Tree <NavigationEntity>().Source(navs).ToNode(m => m.ID, m => m.Title, m => m.ParentId, "#"); Node root = new Node { id = "root", text = _localize.Get("Navigation"), children = node, state = new State { opened = true }, a_attr = new { id = "root" } }; return(Json(root)); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; DateTime dateTime; if (field.Name == "Date" && data.FieldValue.IsNotNullAndWhiteSpace() && !DateTime.TryParse(data.FieldValue, out dateTime)) { message = _localize.Get("{0}的日期格式不正确").FormatWith(field.DisplayName); return(false); } return(true); }
public override ServiceResult <ArticleEntity> Add(ArticleEntity item) { ServiceResult <ArticleEntity> result; if (item.Url.IsNotNullAndWhiteSpace()) { if (GetByUrl(item.Url) != null) { result = new ServiceResult <ArticleEntity>(); result.RuleViolations.Add(new RuleViolation("Url", _localize.Get("URL already exists"))); return(result); } } _eventManager.Trigger(Events.OnArticleAdding, item); result = base.Add(item); if (!result.HasViolation) { _eventManager.Trigger(Events.OnArticleAdded, item); } return(result); }
public ServiceResult <bool> CloseOrder(string orderId) { var order = Get(orderId); if (order != null && order.OrderStatus == (int)OrderStatus.UnPaid) { var serviceResult = _paymentServices.First(m => m.Getway == order.PaymentGateway).CloseOrder(order); if (serviceResult.Result) { order.OrderStatus = (int)OrderStatus.Cancel; Update(order); } return(serviceResult); } ServiceResult <bool> result = new ServiceResult <bool> { Result = false }; result.RuleViolations.Add(new RuleViolation("Error", _localize.Get("Only unpaid order can be closed!"))); return(result); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.Name == "ValidCode" && data.FieldValue.IsNotNullAndWhiteSpace()) { if (!_imageCaptchaService.ValidateCode(data.FieldValue)) { message = _localize.Get("{0} is not correct.").FormatWith(field.DisplayName); return(false); } } return(true); }
public DropDownListDescriptor DataSource(IDictionary <string, string> Data) { this._data = new Dictionary <string, string>(); ILocalize localize = ServiceLocator.GetService <ILocalize>(); foreach (var item in Data) { if (!_data.ContainsKey(item.Key)) { _data.Add(item.Key, localize.Get(item.Value)); } } return(this); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.Name == "ValidCode" && data.FieldValue.IsNotNullAndWhiteSpace()) { string code = _validate.GetCode(); if (!code.Equals(data.FieldValue, StringComparison.InvariantCultureIgnoreCase)) { message = _localize.Get("{0}不正确").FormatWith(field.DisplayName); return(false); } } return(true); }
public IActionResult PostMessage(MessageEntity entity) { if (ModelState.IsValid) { entity.Status = (int)RecordStatus.InActive; var result = _messageService.Add(entity); ModelState.Merge(result); if (!result.HasViolation) { TempData["Message"] = _localize.Get("Thank You for your submit!"); } } return(View(entity)); }
public override ServiceResult <ApplicationSetting> Add(ApplicationSetting item) { lock (ApplicationSetting) { if (base.Get(item.SettingKey) == null) { _settingCache.TryAdd(item.SettingKey, item); return(base.Add(item)); } var result = new ServiceResult <ApplicationSetting>(); result.RuleViolations.Add(new RuleViolation("SettingKey", _localize.Get("The setting key is already exists"))); return(result); } }
public void Handle(object entity, EventArg e) { FormData formData = entity as FormData; if (formData != null && formData.Form.NotificationReceiver.IsNotNullAndWhiteSpace()) { _notificationManager.Send(new RazorEmailMessage { Subject = _localize.Get("New form data"), To = formData.Form.NotificationReceiver.Split(new char[] { '\r', '\n', ',', ';' }, StringSplitOptions.RemoveEmptyEntries), Model = formData, TemplatePath = "~/wwwroot/Plugins/ZKEACMS.FormGenerator/EmailTemplates/FormDataNotification.cshtml" }); } }
public IActionResult Create(List <LanguageEntity> language, string LanKey) { if (_languageService.GetCultures(LanKey).Any()) { ViewBag.LanKey = LanKey; ModelState.AddModelError("LanKey", _localize.Get("翻译键已存在")); return(View(language)); } foreach (var item in language) { item.LanKey = LanKey; _languageService.Add(item); } return(RedirectToAction("Index")); }
public void ResetPassword(UserEntity user) { var dataProtector = _dataProtectionProvider.CreateProtector("ResetPassword"); _notificationManager.Send(new RazorEmailNotice { Subject = _localize.Get("Reset password"), To = new string[] { user.Email }, Model = new ResetPasswordViewModel { Link = $"{_hostOptionProvider.GetOrigin()}/Account/Reset?token={user.ResetToken}&pt={dataProtector.Protect(user.ResetToken)}" }, TemplatePath = "~/EmailTemplates/ResetPassword.cshtml" }); }
public bool Validate(FormField field, FormDataItem data, out string message) { message = string.Empty; if (field.Name == "Phone" && data.FieldValue.IsNotNullAndWhiteSpace()) { if (Regex.IsMatch(data.FieldValue, RegularExpression.ChinesePhone) || Regex.IsMatch(data.FieldValue, RegularExpression.ChineseMobile)) { return(true); } else { message = _localize.Get("Invalid value for {0}.").FormatWith(field.DisplayName); return(false); } } return(true); }
public override ServiceResult <Comments> Add(Comments item) { ServiceResult <Comments> result = base.Add(item); MessageNotificationConfig notifyConfig = _applicationSettingService.Get <MessageNotificationConfig>(); if (notifyConfig.CommentNotifyEmails.IsNotNullAndWhiteSpace()) { _notificationManager.Send(new RazorEmailNotice { Subject = _localize.Get("New comment"), To = notifyConfig.CommentNotifyEmails.Split(new char[] { '\r', '\n', ',', ';' }, StringSplitOptions.RemoveEmptyEntries), Model = item, TemplatePath = "~/wwwroot/Plugins/ZKEACMS.Message/EmailTemplates/CommentNotification.cshtml" }); } return(result); }
public void Handle(object entity, EventArg e) { Comments item = entity as Comments; if (item != null) { MessageNotificationConfig notifyConfig = _applicationSettingService.Get <MessageNotificationConfig>(); if (notifyConfig.CommentNotifyEmails.IsNotNullAndWhiteSpace()) { _notificationManager.Send(new RazorEmailNotice { Subject = _localize.Get("New comment"), To = notifyConfig.CommentNotifyEmails.Split(new char[] { '\r', '\n', ',', ';' }, StringSplitOptions.RemoveEmptyEntries), Model = item, TemplatePath = "~/wwwroot/Plugins/ZKEACMS.Message/EmailTemplates/CommentNotification.cshtml" }); } } }
public PageExistException(ILocalize localize) : base(localize.Get("URL already exists")) { }
public DropDownListDescriptor DataSource <T>() { if (_data == null) { _data = new Dictionary <string, string>(); } Type dataType = typeof(T); if (!dataType.GetTypeInfo().IsEnum) { throw new Exception(dataType.FullName + ",不是枚举类型。"); } string[] text = Enum.GetNames(dataType); ILocalize localize = ServiceLocator.GetService <ILocalize>(); for (int i = 0; i < text.Length; i++) { this._data.Add(Enum.Format(dataType, Enum.Parse(dataType, text[i], true), "d"), localize.Get(text[i])); } return(this); }
public ServiceResult <FormData> SaveForm(IFormCollection formCollection, string formId) { var result = new ServiceResult <FormData>(); var form = _formService.Get(formId); if (form == null) { result.RuleViolations.Add(new RuleViolation("Form", "Form not found!")); return(result); } var formData = new FormData { FormId = formId, Datas = new List <FormDataItem>(), Form = form }; Regex regex = new Regex(@"(\w+)\[(\d+)\]"); foreach (var item in formCollection.Keys) { string id = regex.Replace(item, evaluator => { return(evaluator.Groups[1].Value); }); var field = form.FormFields.FirstOrDefault(m => m.ID == id); if (field != null) { string value = formCollection[item]; FormDataItem dataitem = new FormDataItem { FieldId = field.ID, FieldValue = value, FieldText = field.DisplayName }; if (field.FieldOptions != null) { var option = field.FieldOptions.FirstOrDefault(o => o.Value == value); if (option != null) { dataitem.OptionValue = option.Value; dataitem.FieldValue = option.DisplayText; } } foreach (var validator in _formDataValidators) { if (!validator.Validate(field, dataitem, out string message)) { result.RuleViolations.Add(new RuleViolation(field.DisplayName, message)); return(result); } } formData.Datas.Add(dataitem); } } if (formData.Datas.Any()) { formData.Title = formData.Datas.FirstOrDefault().FieldValue; } result = Add(formData); if (!result.HasViolation && form.NotificationReceiver.IsNotNullAndWhiteSpace()) { _notificationManager.Send(new RazorEmailNotice { Subject = _localize.Get("New form data"), To = form.NotificationReceiver.Split(new char[] { '\r', '\n', ',', ';' }, StringSplitOptions.RemoveEmptyEntries), Model = Get(formData.ID), TemplatePath = "~/wwwroot/Plugins/ZKEACMS.FormGenerator/EmailTemplates/FormDataNotification.cshtml" }); } return(result); }