public ActionResult Save(AppSettingModel model) { if (model.IsNew && !CanAdd) { return GetAddDeniedResult(); } if (!model.IsNew && !CanUpdate) { return GetUpdateDeniedResult(); } if (!ModelState.IsValid) return JsonObject(false, GetModelStateErrors()); var appSetting = model.Map<AppSettingModel, AppSetting>(); appSetting.Name = appSetting.Name.ToStr().Trim(); var result = ServiceHelper.AppSetting.ExecuteDispose(s => s.SaveAppSetting(new SaveRequest { Entity = appSetting })); if (!result.Success) { return JsonObject(false, result.Messages.FirstOrDefault().GetServiceMessageRes()); } foreach (AppSettingType type in Enum.GetValues(typeof(AppSettingType))) { CacheHelper.ClearGetAppSettings(type); } SendNotification(NotifyType.Success, BackendMessage.SaveDataSuccess); return JsonObject(true, string.Empty); }
public ActionResult SaveImage(AppSettingModel model) { var controller = model.ControllerReturn; var action = model.ActionReturn; if (string.IsNullOrWhiteSpace(model.Name)) { SendNotification(NotifyType.Error, Share.Messages.BeScreens.SiteSetting.SiteSetting.NameRequired); return RedirectToAction(action, controller); } #region file hanlder if (Request.Files["fileImage"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage"].FileName)) { var file = Request.Files["fileImage"]; var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } if (!string.IsNullOrWhiteSpace(model.OldImagePath)) { DeleteImageFile(model.OldImagePath); } model.ImagePath = Guid.NewGuid() + extension; var filePath = PhysicalDataFilePath(model.ImagePath); file.SaveAs(filePath); } else if (string.IsNullOrWhiteSpace(model.ImagePath) && !string.IsNullOrWhiteSpace(model.OldImagePath)) { DeleteImageFile(model.OldImagePath); } if (Request.Files["fileImage2"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage2"].FileName)) { var file = Request.Files["fileImage2"]; var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } if (!string.IsNullOrWhiteSpace(model.OldImagePath2)) { DeleteImageFile(model.OldImagePath2); } model.ImagePath2 = Guid.NewGuid() + extension; var filePath = PhysicalDataFilePath(model.ImagePath2); file.SaveAs(filePath); } else if (string.IsNullOrWhiteSpace(model.ImagePath2) && !string.IsNullOrWhiteSpace(model.OldImagePath2)) { DeleteImageFile(model.OldImagePath2); } if (Request.Files["fileImage3"] != null && !string.IsNullOrWhiteSpace(Request.Files["fileImage3"].FileName)) { var file = Request.Files["fileImage3"]; var extension = Path.GetExtension(file.FileName).ToStr(); if (!SiteUtils.IsImageFile(file.FileName)) { return JsonObject(false, BackendMessage.FileTypeIsInvalid); } if (!SiteUtils.ImageSizeIsValid(file.ContentLength)) { return JsonObject(false, BackendMessage.FileMaxSize5MB); } if (!string.IsNullOrWhiteSpace(model.OldImagePath3)) { DeleteImageFile(model.OldImagePath3); } model.ImagePath3 = Guid.NewGuid() + extension; var filePath = PhysicalDataFilePath(model.ImagePath3); file.SaveAs(filePath); } else if (string.IsNullOrWhiteSpace(model.ImagePath3) && !string.IsNullOrWhiteSpace(model.OldImagePath3)) { DeleteImageFile(model.OldImagePath3); } #endregion var appSetting = model.Map<AppSettingModel, AppSetting>(); appSetting.Value = model.ImagePath; appSetting.Name = appSetting.Name.ToStr().Trim(); var result = ServiceHelper.AppSetting.ExecuteDispose(s => s.SaveAppSetting(new SaveRequest { Entity = appSetting })); if (!result.Success) { return JsonObject(false, result.Messages.FirstOrDefault().GetServiceMessageRes()); } if (!string.IsNullOrWhiteSpace(model.Name2)) { appSetting.Id = model.Id2; appSetting.Value = model.ImagePath2; appSetting.Name = model.Name2.ToStr().Trim(); result = ServiceHelper.AppSetting.ExecuteDispose(s => s.SaveAppSetting(new SaveRequest { Entity = appSetting })); if (!result.Success) { return JsonObject(false, result.Messages.FirstOrDefault().GetServiceMessageRes()); } } if (!string.IsNullOrWhiteSpace(model.Name3)) { appSetting.Id = model.Id3; appSetting.Value = model.ImagePath3; appSetting.Name = model.Name3.ToStr().Trim(); result = ServiceHelper.AppSetting.ExecuteDispose(s => s.SaveAppSetting(new SaveRequest { Entity = appSetting })); if (!result.Success) { return JsonObject(false, result.Messages.FirstOrDefault().GetServiceMessageRes()); } } foreach (AppSettingType type in Enum.GetValues(typeof(AppSettingType))) { CacheHelper.ClearGetAppSettings(type); } SendNotification(NotifyType.Success, BackendMessage.SaveDataSuccess); return JsonObject(true, string.Empty); }