public ActionResult Edit(int id = 0) { var module = _moduleService.Modules.FirstOrDefault(c => c.Id == id); if (module == null) { return(PartialView("Create", new ModuleVM())); } ViewBag.ParentModuleList = _moduleService.Modules .Where(c => c.IsMenu == true && c.Enabled == true && c.ParentId == null) .Select(c => new SelectListItem() { Text = c.Name, Value = c.Id.ToString(), Selected = (module.ParentId.HasValue && (module.ParentId.Value == c.Id)) }) .ToList(); var model = new ModuleVM() { Id = module.Id, Name = module.Name, ParentId = module.ParentId, LinkUrl = module.LinkUrl, IsMenu = module.IsMenu, Code = module.Code, Description = module.Description, Enabled = module.Enabled, }; return(PartialView("Create", model)); }
public ActionResult Create() { var vm = new ModuleVM(); ViewBag.ParentModuleList = GetMenuDropDownListSource(); return(PartialView(vm)); }
public Result Insert(ModuleVM model) { try { Module oldModule = Modules.FirstOrDefault(c => c.Name == model.Name.Trim()); if (oldModule != null) { return(new Result(ResultType.Warning, "数据库中已经存在相同名称的模块,请修改后重新提交!")); } var entity = new Module { Name = model.Name.Trim(), ParentId = model.ParentId, LinkUrl = model.LinkUrl, IsMenu = model.IsMenu, Code = model.Code, Description = model.Description, Enabled = model.Enabled, UpdateTime = DateTime.Now }; _moduleRepository.Insert(entity); return(new Result(ResultType.Success, "新增数据成功!")); } catch { return(new Result(ResultType.Error, "新增数据失败,数据库插入数据时发生了错误!")); } }
public int Insert(ModuleVM form) { if (string.IsNullOrEmpty(form.Name)) { throw new BaseException(SuperConstants.AJAX_RETURN_STATE_ERROR, "模块名称为空"); } if (form.ParentId == 0) { throw new BaseException(SuperConstants.AJAX_RETURN_STATE_ERROR, "上级模块为空"); } if (string.IsNullOrEmpty(form.LinkUrl)) { throw new BaseException(SuperConstants.AJAX_RETURN_STATE_ERROR, "链接地址为空"); } if (form.Code == 0) { throw new BaseException(SuperConstants.AJAX_RETURN_STATE_ERROR, "模块编号为空"); } Sys_Module module = new Sys_Module(); Ext.CopyFrom(module, form); module.IsMenu = true; module.UpdateDate = DateTime.Now; return(this._moduleRepository.Insert(ContextDB.managerDBContext, module)); }
public Result Update(ModuleVM model) { try { var module = Modules.FirstOrDefault(c => c.Id == model.Id); if (module == null) { throw new Exception(); } var other = Modules.FirstOrDefault(c => c.Id != model.Id && c.Name == model.Name.Trim()); if (other != null) { return(new Result(ResultType.Warning, "数据库中已经存在相同名称的模块,请修改后重新提交!")); } module.Name = model.Name.Trim(); module.ParentId = model.ParentId; module.LinkUrl = model.LinkUrl; module.IsMenu = model.IsMenu; module.Code = model.Code; module.Description = model.Description; module.Enabled = model.Enabled; module.UpdateTime = DateTime.Now; _moduleRepository.Update(module); return(new Result(ResultType.Success, "更新数据成功!")); } catch { return(new Result(ResultType.Error, "更新数据失败!")); } }
public ActionResult Index(ModuleVM form) { Page <Sys_Module> page = this._moduleService.FindPage(form); this.SavePage(page, form); return(View()); }
public void Delete(ModuleVM form) { using (TransactionScope scope = new TransactionScope()) { this._moduleRepository.Delete(ContextDB.managerDBContext, t => t.Id == form.Id); this._permissionRepository.Delete(ContextDB.managerDBContext, t => t.ModuleId == form.Id); scope.Complete(); } }
public void EditModule(ModuleVM model) { var module = context.Modules.Single(m => m.Id == model.Id); module.Name = model.Name; module.Description = model.Description; module.Tags = model.Tags; context.SaveChanges(); }
public static ModuleVM MapResource(Module entity) { ModuleVM res = new ModuleVM { ModuleId = entity.ModuleId, Title = entity.Title, Credits = entity.Credits }; return(res); }
public ActionResult Create(ModuleVM vm) { if (!ModelState.IsValid) { return(Json(new OperationResult(OperationResultType.ParamError, "参数错误,请重新输入"))); } var result = _moduleService.Insert(vm); result.Message = result.Message ?? result.ResultType.GetDescription(); return(Json(result)); }
public ActionResult Edit(ModuleVM moduleVM) { if (!ModelState.IsValid) { return(Json(new OperationResult(OperationResultType.ParamError, "参数错误,请重新检查输入"))); } var result = _moduleService.Update(moduleVM); result.Message = result.Message ?? result.ResultType.GetDescription(); return(Json(result)); }
public void CreateNewModule(ModuleVM model) { context.Modules.Add(new Module() { Description = model.Description, Name = model.Name, Tags = model.Tags //,Tests = model.Tests }); context.SaveChanges(); }
public async Task <ActionResult> Edit(ModuleVM module) { if (ModelState.IsValid) { await modulesService.UpdateAsync(module); return(RedirectToAction("Index")); } return(View(module)); }
public static Module MapResourceVM(ModuleVM vm) { Module res = new Module { ModuleId = vm.ModuleId, Title = vm.Title, Credits = vm.Credits }; return(res); }
public async Task <bool> UpdateAsync(ModuleVM module) { var content = new StringContent(JsonConvert.SerializeObject(module), Encoding.UTF8, "application/json"); var response = await this.httpClient.PutAsync($"/api/modules/{module.ModuleId}", content); if (response.IsSuccessStatusCode) { return(true); } return(false); }
public ActionResult ModuleEdit(ModuleVM form) { List <Sys_Module> list = this._moduleService.GetModuleList().Where(t => t.ParentId == null || t.ParentId == 0).ToList(); ViewData["ModuleList"] = list; Sys_Module model = this._moduleService.GetModule(form); ViewBag.form = model; ViewData["type"] = "edit"; return(View("ModuleInsert")); }
public async Task <ActionResult> Create(ModuleVM vm) { if (ModelState.IsValid) { vm.ModuleLib = vm.ModuleLib; await modulesService.Create(vm); return(RedirectToAction("Index")); } return(View(vm)); }
public ActionResult Create() { var vm = new ModuleVM(); ViewBag.ParentModuleList = _moduleService.Modules .Where(c => c.IsMenu == true && c.Enabled == true && c.ParentId == null) .Select(c => new SelectListItem() { Text = c.Name, Value = c.Id.ToString() }) .ToList(); return(PartialView(vm)); }
public ActionResult Index() { if (!Convert.ToBoolean(Session["IsLogged"])) { return(RedirectToAction("Index", "Home")); } var moduleViewModel = new ModuleVM { ApplicationList = new SelectList(_unitOfWork.ApplicationRepository.Get(), "ApplicationID", "Title") }; return(View(moduleViewModel)); }
public Page <Sys_Module> FindPage(ModuleVM form) { Expression <Func <Sys_Module, bool> > predicate = Ext.True <Sys_Module>(); if (!string.IsNullOrEmpty(form.Name)) { predicate = predicate.And(s => s.Name.Contains(form.Name)); } if (!string.IsNullOrEmpty(form.EnabledStr)) { if (form.EnabledStr.Equals("1")) { predicate = predicate.And(s => s.Enabled == true); } else { predicate = predicate.And(s => s.Enabled == false); } } OrderModelField idOrder = new OrderModelField { PropertyName = "Id", IsDESC = false }; OrderModelField[] orderByExpression = new OrderModelField[] { idOrder }; Page <Sys_Module> page = this._moduleRepository.FindPage(ContextDB.managerDBContext, predicate, orderByExpression, form.page, form.rows); if (page != null & page.ResultList.Count > 0) { List <Sys_Module> list = this._moduleRepository.Entities(ContextDB.managerDBContext, t => 1 == 1); if (list != null && list.Count > 0) { foreach (var item in page.ResultList) { Sys_Module model = list.Where(t => t.Id == item.ParentId).SingleOrDefault(); if (model != null) { item.ParentName = model.Name; } } } } return(page); }
public ActionResult Index() { if (!Convert.ToBoolean(Session["IsLogged"])) { return(RedirectToAction("Index", "Home")); } var moduleViewModel = new ModuleVM { Modules = _unitOfWork.ModuleRepository.GetAll().Where(s => s.IsDelete == false).OrderByDescending(s => s.SetOn), ApplicationList = new SelectList(_unitOfWork.ApplicationRepository.Get().Where(a => a.IsActive.Equals(true) && a.IsDelete.Equals(false)), "ApplicationID", "Title") }; ViewBag.ModuleList = moduleViewModel.Modules.ToList(); return(View(moduleViewModel)); }
public int Update(ModuleVM form) { Sys_Module module = this._moduleRepository.Entity(ContextDB.managerDBContext, t => t.Id == form.Id); if (module != null) { module.UpdateDate = DateTime.Now; module.Name = form.Name; module.ParentId = form.ParentId; module.LinkUrl = form.LinkUrl; module.Code = form.Code; module.Enabled = form.Enabled; } return(this._moduleRepository.Update(ContextDB.managerDBContext, module)); }
public string ModuleEdit(ModuleVM form, int type = 0) { try { this._moduleService.Update(form); return(ResponseJson.Success()); } catch (BaseException ex) { _logger.Info(ex.GetMessage()); return(ResponseJson.Error(ex.GetExceptionFlag(), ex.GetMessage())); } catch (Exception ex) { _logger.Info(ex.Message); return(ResponseJson.Error(ex.Message)); } }
public ActionResult Update(Guid?id) { if (id == null) { return(Content("非法参数")); } var viewModel = new ModuleVM(); services.Command((db) => { var cfg = new MapperConfigurationExpression(); cfg.CreateMap <Module, ModuleVM>(); cfg.CreateMap <V_Module, V_ModuleVM>(); Mapper.Initialize(cfg); viewModel = Mapper.Map <ModuleVM>(db.Queryable <Module>().InSingle(id)); ViewData["ModuleList"] = Common.ModuleDropDownList(Mapper.Map <List <V_ModuleVM> >(db.Queryable <V_Module>().Where(c => true).ToList()), viewModel.ParentID); }); return(View(viewModel)); }
public JsonResult Insert(ModuleVM viewModel) { var clientResult = new JsonData <object>(); var sessionModel = Session[Keys.SessionKey] as MemberSessionVM; viewModel.LogMemberID = sessionModel.MemberID; viewModel.Remark = string.IsNullOrEmpty(viewModel.Remark) ? viewModel.Name : viewModel.Remark; viewModel.Iconfont = string.IsNullOrEmpty(viewModel.Iconfont) ? "icon-backend-file" : viewModel.Iconfont; Mapper.Initialize(u => u.CreateMap <ModuleVM, Module>()); var model = Mapper.Map <Module>(viewModel); model.ModuleID = Guid.NewGuid(); services.Command((db) => { db.Insert <Module>(model); clientResult.SetClientData("y", "操作成功", new { id = model.ModuleID }); }); return(Json(clientResult)); }
public OperationResult Update(ModuleVM model) { try { var modules = _moduleReps.FirstOrDefault(c => c.Id == model.Id); if (modules == null) { throw new Exception(); } var other = _moduleReps.FirstOrDefault(c => c.Id != model.Id && c.Name == model.Name.Trim()); if (other != null) { return(new OperationResult(OperationResultType.Warning, "数据库中已经存在相同名称的模块,请修改后重新提交!")); } modules.Name = model.Name.Trim(); modules.ParentId = model.ParentId; modules.LinkUrl = model.LinkUrl; modules.IsMenu = model.IsMenu; modules.Code = model.Code; modules.Description = model.Description; modules.Enabled = model.Enabled; modules.UpdateDate = DateTime.Now; modules.Icon = model.Icon; _moduleReps.Update(modules); //禁用模块,则模块下的权限也要禁用 if (!modules.Enabled) { _permissionReps.Update(c => c.ModuleId == modules.Id, u => new Permissions() { Enabled = false }); } return(new OperationResult(OperationResultType.Success, "更新数据成功!")); } catch { return(new OperationResult(OperationResultType.Error, "更新数据失败!")); } }
public ActionResult Edit(int id = 0) { var modules = _moduleService.GetModule(c => c.Id == id); if (modules == null) { return(PartialView("Create", new ModuleVM())); } var menuSource = GetMenuDropDownListSource(); if (modules.ParentId.HasValue) { foreach (var item in menuSource) { if (modules.ParentId.Value.ToString() == item.Value) { item.Selected = true; break; } } } ViewBag.ParentModuleList = menuSource; var model = new ModuleVM() { Id = modules.Id, Name = modules.Name, ParentId = modules.ParentId, LinkUrl = modules.LinkUrl, IsMenu = modules.IsMenu, Code = modules.Code, Description = modules.Description, Enabled = modules.Enabled, Icon = modules.Icon }; return(PartialView("Create", model)); }
public string GetModule(int Id) { Module results = new Module(); ModuleVM returnResults = new ModuleVM(); string json; using (ApplicationDbContext data = new ApplicationDbContext()) { results = data.Modules.FirstOrDefault(X => X.Id == Id); } returnResults.Name = results.Name; returnResults.Description = results.Description; returnResults.QuestionCount = results.QuestionCount; returnResults.Duration = results.Duration; returnResults.MinPassScore = results.MinPassScore; returnResults.MaximumScore = results.MaximumScore; json = JsonConvert.SerializeObject(returnResults); return(json); }
public JsonResult Update(ModuleVM viewModel) { var clientResult = new JsonData <object>() { }; if (viewModel.ModuleID == null) { clientResult.SetClientData("n", "非法参数"); } viewModel.Remark = string.IsNullOrEmpty(viewModel.Remark) ? viewModel.Name : viewModel.Remark; viewModel.Iconfont = string.IsNullOrEmpty(viewModel.Iconfont) ? "icon-backend-file" : viewModel.Iconfont; if (viewModel.ModuleID == viewModel.ParentID) { clientResult.SetClientData("n", "上级栏目不能是本身栏目"); } else { services.Command((db) => { db.Update <Module>(new { viewModel.Enable, viewModel.Iconfont, viewModel.Name, viewModel.ParentID, viewModel.Remark, viewModel.Sort, viewModel.TagAttr, UpdateTime = DateTime.Now }, u => u.ModuleID == viewModel.ModuleID); clientResult.SetClientData("y", "操作成功"); }); } return(Json(clientResult)); }
public Sys_Module GetModule(ModuleVM form) { return(this._moduleRepository.Entity(ContextDB.managerDBContext, t => t.Id == form.Id)); }