public ActionResult SaveConfig(SystemConfigViewModel configViewModel) { var result = new DataJsonResult(); var config = new SystemConfig(); config.StockWarning = configViewModel.StockWarning; config.CrashApplyOutTime = configViewModel.CrashApplyOutTime; config.ReduceStock = configViewModel.ReduceStock; config.RecommendIntegral = configViewModel.RecommendIntegral; config.ConsumptionIntegral = configViewModel.ConsumptionIntegral; config.DiscountRate = configViewModel.DiscountRate; config.MaxLevel = 3;//configViewModel.MaxLevel; foreach (var rate in configViewModel.Rates) { config.Rates.Add(rate); } //水印 config.WaterMark.WaterMarkType = configViewModel.WaterMarkType; config.WaterMark.Opacity = configViewModel.Opacity; config.WaterMark.Position = configViewModel.Position; config.WaterMark.WaterMarkText = configViewModel.WaterMarkText; if (!configViewModel.WaterMarkImage.Equals(Guid.Empty) && _storageFileService.ReplaceFile(Guid.Empty, ConfigModule.Instance.InnerKey, ConfigModule.Instance.InnerDisplayName, configViewModel.WaterMarkImage, "WaterMarkImage")) { config.WaterMark.MarkImage = _storageFileService.GetFiles(Guid.Empty, ConfigModule.Instance.InnerKey, "WaterMarkImage").FirstOrDefault(); } if (!_configService.Save(config)) { result.ErrorMessage = "异常错误,配置文件保存失败"; } return(Json(result)); }
public async Task <IActionResult> SystemConfigDetails(SystemConfigViewModel model) { if (ModelState.IsValid) { try { model._context = _context; model._securityOptions = _securityOptions; model._user = User; Guid configID = await model.Save(); if (configID != Guid.Empty) { return(RedirectToAction("SystemConfigDetails", new { ID = configID, Success = true })); } else { ViewBag.Error = model.errorMessage; } } catch (Exception ex) { HelperFunctions.Log(_context, PublicEnums.LogLevel.LEVEL_EXCEPTION, "Controllers.MasterDataController.SystemConfigDetails", ex.Message, User, ex); ViewBag.Error = "An error occurred. Please try again later."; } } return(View(model)); }
public async Task <bool> CreateOrUpdateConfigAsync(SystemConfigViewModel config) { try { var currentConfig = await GetConfigByCodeAsync(config.Code); if (currentConfig == null) { var model = _mapper.Map <SystemConfigViewModel, SystemConfig>(config); await Add(model); return(await _unitOfWork.Commit()); } else { currentConfig.ValueNumber = config.ValueNumber; currentConfig.ValueString = config.ValueString; return(await UpdateConfigAsync(currentConfig)); } } catch (Exception e) { } return(false); }
public static void UpdateSystemConfig(this SystemConfig systemConfig, SystemConfigViewModel systemConfigVM) { systemConfig.ID = systemConfigVM.ID; systemConfig.Code = systemConfigVM.Code; systemConfig.ValueString = systemConfigVM.ValueString; systemConfig.ValueInt = systemConfigVM.ValueInt; }
public async Task <IActionResult> SystemConfigDetails(Guid ID, bool Success = false) { SystemConfigViewModel model = new SystemConfigViewModel(); try { model._context = _context; model._securityOptions = _securityOptions; model.SystemConfigurationID = ID; model._user = User; await model.PopulateModel(); } catch (Exception ex) { HelperFunctions.Log(_context, PublicEnums.LogLevel.LEVEL_EXCEPTION, "Controllers.MasterDataController.SystemConfigDetails", ex.Message, User, ex); ViewBag.Error = "An error occurred. Please try again later."; } //Set message if redirected from save if (Success) { ViewBag.Success = "Configuration updated successfully"; } ViewData.Model = model; return(View()); }
public IActionResult SaveEntity(SystemConfigViewModel systemConfigVm) { try { if (systemConfigVm.Id.ToString() == CommonConstants.DefaultGuid) { //if (!_systemConfigService.CheckOrderAddPost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự đã tồn tại"); //if (!_systemConfigService.CheckHomeOrderAddUpdatePost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự trang chủ đã tồn tại"); //if (!_systemConfigService.CheckHotOrderAddUpdatePost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự khu vực HOT đã tồn tại"); //if (_systemConfigService.CheckOrderAddPost(systemConfigVm) // && _systemConfigService.CheckHomeOrderAddUpdatePost(systemConfigVm) // && _systemConfigService.CheckHotOrderAddUpdatePost(systemConfigVm)) // _systemConfigService.Add(systemConfigVm); _systemConfigService.Add(systemConfigVm); } else { //if (!_systemConfigService.CheckOrderUpdatePost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự đã tồn tại"); //if (!_systemConfigService.CheckHomeOrderAddUpdatePost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự trang chủ đã tồn tại"); //if (!_systemConfigService.CheckHotOrderAddUpdatePost(systemConfigVm)) // ModelState.AddModelError("", // "Thứ tự khu vực HOT đã tồn tại"); //if (_systemConfigService.CheckOrderUpdatePost(systemConfigVm) // && _systemConfigService.CheckHomeOrderAddUpdatePost(systemConfigVm) // && _systemConfigService.CheckHotOrderAddUpdatePost(systemConfigVm)) // _systemConfigService.Update(systemConfigVm); _systemConfigService.Update(systemConfigVm); } //if (!ModelState.IsValid) //{ // IEnumerable<ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); // return new BadRequestObjectResult(allErrors); //} _systemConfigService.Save(); return(new OkObjectResult(systemConfigVm)); } catch (Exception ex) { throw ex; } }
public HttpResponseMessage Detail(HttpRequestMessage request, int id) { return(CreateHttpResponse(request, () => { SystemConfig systemConfig = _systemConfigService.Detail(id); SystemConfigViewModel systemConfigVm = Mapper.Map <SystemConfigViewModel>(systemConfig); return request.CreateResponse(HttpStatusCode.OK, systemConfigVm); })); }
public static void UpdateSystemConfig(this SystemConfig systemConfig, SystemConfigViewModel systemConfigVm) { systemConfig.Name = systemConfigVm.Name; systemConfig.Value1 = systemConfigVm.Value1; systemConfig.Value2 = systemConfigVm.Value2; systemConfig.Value3 = systemConfigVm.Value3; systemConfig.Value4 = systemConfigVm.Value4; systemConfig.Value5 = systemConfigVm.Value5; systemConfig.Status = systemConfigVm.Status; }
public async Task <ActionResult> Edit([Bind(Include = "Code,ValueString,ValueNumber")] SystemConfigViewModel model) { var isUpdate = await _systemConfigService.CreateOrUpdateConfigAsync(model); if (isUpdate) { return(RedirectToAction("Index")); } return(RedirectToAction("Error", "Response", new { message = "update config failure" })); }
public SystemConfig(SystemConfigViewModel systemConfigVm) { Id = systemConfigVm.Id; Name = systemConfigVm.Name; Value1 = systemConfigVm.Value1; Value2 = systemConfigVm.Value2; Value3 = systemConfigVm.Value3; Value4 = systemConfigVm.Value4; Value5 = systemConfigVm.Value5; Status = systemConfigVm.Status; }
public ActionResult SystemConfigResult(SystemConfigViewModel model) { SetConfiguration("ServerUrl", model.ServerUrl); SetConfiguration("LinkEnableDuration", model.LinkEnableDuration); SetConfiguration("CacheDuration", model.CacheDuration); SetConfiguration("EnableAccountAutoChange", model.EnableAccountAutoChange); SetConfiguration("ChangeThreshold", model.ChangeThreshold); SetConfiguration("ClientId", model.ClientId); SetConfiguration("ClientSecret", model.ClientSecret); return(RedirectToAction("Index", new { message = ManageMessageId.Success })); }
public async Task <bool> UpdateConfigAsync(SystemConfigViewModel config) { try { var model = _mapper.Map <SystemConfigViewModel, SystemConfig>(config); await Update(model); return(await _unitOfWork.Commit()); } catch (Exception e) { } return(false); }
public async Task <IActionResult> Add([FromBody] SystemConfigViewModel systemConfigVm) { var hasPermission = await _authorizationService.AuthorizeAsync(User, "SYSTEMCONFIG", Operations.Create); if (hasPermission.Succeeded == false) { return(new BadRequestObjectResult(CommonConstants.Forbidden)); } if (ModelState.IsValid) { _systemConfigService.Add(systemConfigVm); _systemConfigService.SaveChanges(); return(new OkObjectResult(systemConfigVm.Id)); } return(new BadRequestObjectResult(ModelState)); }
public ActionResult SystemConfiguration() { ViewBag.managesystem = "active"; SystemConfigViewModel systemModel = new SystemConfigViewModel(); var data = db.SystemConfigurations.Select(x => x); systemModel.SupportEmail = data.Where(x => x.Key == "SupportEmailAddress").FirstOrDefault().Value; systemModel.SupportContact = data.Where(x => x.Key == "SupportContactNumber").FirstOrDefault().Value; systemModel.FacebookURL = data.Where(x => x.Key == "FBICON").FirstOrDefault().Value; systemModel.TwitterURL = data.Where(x => x.Key == "TWITTERICON").FirstOrDefault().Value; systemModel.LinkedinURL = data.Where(x => x.Key == "LNICON").FirstOrDefault().Value; systemModel.EmailAddresses = data.Where(x => x.Key == "EmailAddressesForNotify").FirstOrDefault().Value; return(View(systemModel)); }
public IActionResult SaveEntity(SystemConfigViewModel model) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } if (model.Id == 0) { _systemConfigService.Create(model); } else { _systemConfigService.Update(model); } _systemConfigService.Save(); return(new OkObjectResult(model)); }
public HttpResponseMessage Update(HttpRequestMessage request, SystemConfigViewModel systemConfigVm) { return(CreateHttpResponse(request, () => { if (ModelState.IsValid) { SystemConfig systemConfigDb = _systemConfigService.Detail(systemConfigVm.ID); systemConfigDb.UpdateSystemConfig(systemConfigVm); _systemConfigService.Update(systemConfigDb); _systemConfigService.SaveChange(); return request.CreateResponse(HttpStatusCode.Created, systemConfigVm); } else { return request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } })); }
public HttpResponseMessage Post(HttpRequestMessage request, SystemConfigViewModel systemConfigVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { SystemConfig newSystemConfig = new SystemConfig(); newSystemConfig.UpdateSystemConfig(systemConfigVm); var category = _systemConfigService.Add(newSystemConfig); _systemConfigService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.Created, category); } return response; })); }
public HttpResponseMessage Put(HttpRequestMessage request, SystemConfigViewModel systemConfigVm) { return(CreateHttpResponse(request, () => { HttpResponseMessage response = null; if (!ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { var systemConfigDb = _systemConfigService.GetByID(systemConfigVm.ID); systemConfigDb.UpdateSystemConfig(systemConfigVm); _systemConfigService.Update(systemConfigDb); _systemConfigService.SaveChanges(); response = request.CreateResponse(HttpStatusCode.OK); } return response; })); }
public ActionResult SystemConfiguration(SystemConfigViewModel sysModel) { var user = db.Users.FirstOrDefault(x => x.Email == User.Identity.Name); if (ModelState.IsValid) { var data = db.SystemConfigurations.Select(x => x); data.Where(x => x.Key == "SupportEmailAddress").FirstOrDefault().Value = sysModel.SupportEmail; data.Where(x => x.Key == "SupportContactNumber").FirstOrDefault().Value = sysModel.SupportContact; data.Where(x => x.Key == "FBICON").FirstOrDefault().Value = sysModel.FacebookURL; data.Where(x => x.Key == "TWITTERICON").FirstOrDefault().Value = sysModel.TwitterURL; data.Where(x => x.Key == "LNICON").FirstOrDefault().Value = sysModel.LinkedinURL; if (sysModel.EmailAddresses == null) { data.Where(x => x.Key == "EmailAddressesForNotify").FirstOrDefault().Value = "NA"; } else { data.Where(x => x.Key == "EmailAddressesForNotify").FirstOrDefault().Value = sysModel.EmailAddresses; } if (sysModel.NotePicture != null) { string noteName = System.IO.Path.GetFileName(sysModel.NotePicture.FileName); //get file name string defaultFilename = Directory.GetFiles(Server.MapPath("~/Content/image/default-note-img/")).FirstOrDefault(); //get path string finalfilename = System.IO.Path.GetFileName(defaultFilename); //get already saved file name string PathImage = Request.MapPath("~/Content/image/default-note-img" + "/" + finalfilename); //delete prev file FileInfo file = new FileInfo(PathImage); if (file.Exists) { file.Delete(); } string notefilepath = "~/Content/image/default-note-img/"; string notefinalfilepath = Path.Combine(Server.MapPath(notefilepath), noteName); sysModel.NotePicture.SaveAs(notefinalfilepath); //save image in folder //store path in database data.Where(x => x.Key == "DefaultNoteDisplayPicture").FirstOrDefault().Value = notefilepath + noteName; } if (sysModel.UserPicture != null) { string userName = System.IO.Path.GetFileName(sysModel.UserPicture.FileName); string defaultFilename = Directory.GetFiles(Server.MapPath("~/Content/image/default-user-img/")).FirstOrDefault(); string finalfilename = System.IO.Path.GetFileName(defaultFilename); string PathImage = Request.MapPath("~/Content/image/default-user-img" + "/" + finalfilename); FileInfo file = new FileInfo(PathImage); if (file.Exists) { file.Delete(); } string notefilepath = "~/Content/image/default-user-img/"; string notefinalfilepath = Path.Combine(Server.MapPath(notefilepath), userName); sysModel.UserPicture.SaveAs(notefinalfilepath); data.Where(x => x.Key == "DefaultMemberDisplayPicture").FirstOrDefault().Value = notefilepath + userName; } foreach (var item in data) { item.ModifiedDate = DateTime.Now; } db.SaveChanges(); ViewBag.sucess = "Record Updated Sucessfully"; return(View()); } return(View()); }
public void Update(SystemConfigViewModel slideVM) { var slide = slideVM.AddModel(); _systemRepository.Update(slide); }
public void Add(SystemConfigViewModel systemConfig) { _systemConfigRepository.Add(_mapper.Map <SystemConfig>(systemConfig)); }
public static SystemConfig AddModel(this SystemConfigViewModel addModel) { return(Mapper.Map <SystemConfig>(addModel)); }