public void Update(UpdateRoleInput input) { input.Validate(); Sys_Role role = this.DbContext.QueryByKey <Sys_Role>(input.Id, true); role.NotNull("角色不存在"); AceMapper.Map(input, role); string[] permissionIds = input.GetPermissionIds(); List <Sys_RoleAuthorize> roleAuthorizeEntitys = this.CreateRoleAuthorizes(role.Id, permissionIds); this.DbContext.DoWithTransaction(() => { this.DbContext.Update(role); this.DbContext.Delete <Sys_RoleAuthorize>(a => a.RoleId == role.Id); foreach (var roleAuthorizeEntity in roleAuthorizeEntitys) { this.DbContext.Insert(roleAuthorizeEntity); } }); }
public void UpdateModule(UpdateModuleInput input) { input.Validate(); var entity = _accountRepository.GetById <Sys_Module>(input.Id); AceMapper.Map(input, entity); _accountRepository.Update(entity); }
public void AddModule(AddModuleInput input) { input.Validate(); Sys_Module sys_Module = new Sys_Module(); AceMapper.Map(input, sys_Module); _accountRepository.Insert(sys_Module); }
public void Add(AddUsers_RoleInput input) { input.Validate(); Users_Role role = this.CreateEntity <Users_Role>(null, null); AceMapper.Map(input, role); this.DbContext.DoWithTransaction(() => { this.DbContext.Insert(role); }); }
public string Add(AddDocumentInput input) { input.Validate(); WikiDocumentDetail detail = AceMapper.Map<WikiDocumentDetail>(input); detail.Id = IdHelper.CreateSnowflakeId().ToString(); detail.IsDeleted = false; detail.CreationTime = DateTime.Now; this.DbContext.Insert(detail); return detail.Id; }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { /* NLog */ this._env.ConfigureNLog(Path.Combine("configs", "nlog.config")); loggerFactory.AddNLog(); app.AddNLogWeb(); Globals.ServiceProvider = app.ApplicationServices; AceMapper.InitializeMap(); /* 初始化 AutoMapper */ if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseBrowserLink(); } else { app.UseExceptionHandler("/Home/Error"); } app.UseStaticFiles(); app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, AutomaticAuthenticate = true, }); app.UseSession(); app.UseMvc(routes => { routes.MapRoute( name: "area", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
public void Update(UpdateUsers_RoleInput input) { input.Validate(); Users_Role role = this.DbContext.QueryByKey <Users_Role>(input.ID, true); role.NotNull("角色不存在"); AceMapper.Map(input, role); this.DbContext.DoWithTransaction(() => { this.DbContext.Update(role); }); }
/// <summary> /// 传入一个 dto 对象插入数据。dto 需要与实体建立映射关系,否则会报错 /// </summary> /// <typeparam name="TEntity"></typeparam> /// <typeparam name="TDto"></typeparam> /// <param name="dbContext"></param> /// <param name="dto"></param> /// <returns></returns> public static TEntity InsertFromDto <TEntity, TDto>(this IDbContext dbContext, TDto dto) { /* * 支持自动设置 主键=guid * 支持自动设置 CreationTime=DateTime.Now * 支持自动设置 IsDeleted=false */ Utils.CheckNull(dto); TEntity entity = AceMapper.Map <TEntity>(dto); Type entityType = typeof(TEntity); TypeDescriptor typeDescriptor = TypeDescriptor.GetDescriptor(entityType); /* 设置 主键=guid */ if (typeDescriptor.PrimaryKeys.Count < 2) /* 只有无主键或单一主键的时候 */ { MappingMemberDescriptor primaryKeyDescriptor = typeDescriptor.PrimaryKeys.FirstOrDefault(); if (primaryKeyDescriptor != null && primaryKeyDescriptor.IsAutoIncrement == false) { var keyValue = primaryKeyDescriptor.GetValue(entity); if (keyValue.IsDefaultValueOfType(primaryKeyDescriptor.MemberInfoType) || string.Empty.Equals(keyValue)) { /* 如果未设置主键值,则自动设置为 guid */ if (primaryKeyDescriptor.MemberInfoType == typeof(string)) { primaryKeyDescriptor.SetValue(entity, IdHelper.CreateGuid()); } else if (primaryKeyDescriptor.MemberInfoType.GetUnderlyingType() == typeof(Guid)) { primaryKeyDescriptor.SetValue(entity, Guid.NewGuid()); } } } } /* 设置 CreationTime=DateTime.Now */ SetValueIfNeeded(entity, typeDescriptor, "CreationTime", DateTime.Now); /* 设置 IsDeleted=false */ SetValueIfNeeded(entity, typeDescriptor, "IsDeleted", false); return(dbContext.Insert(entity)); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting) { this._env.ConfigureNLog(Path.Combine("configs", "nlog.config")); loggerFactory.AddNLog(); Globals.Services = app.ApplicationServices; AceMapper.InitializeMap(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); app.UseStaticFiles(); app.UseAuthentication(); app.UseCookiePolicy(); app.UseSession(); IRegisterService register = RegisterService.Start(env, senparcSetting.Value).UseSenparcGlobal(); register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value) .RegisterWxOpenAccount(senparcWeixinSetting.Value, "【TMS】小程序") .RegisterTenpayV3(senparcWeixinSetting.Value, "【TMS】公众号"); app.UseMvc(routes => { routes.MapRoute( name: "area", template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"); routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); }
//[ValidateAntiForgeryToken] public ActionResult Add(AddRoleInput input) { input.Validate(); var services = CreateService <IAccountAppService>(); Sys_Role role = new Sys_Role(); AceMapper.Map(input, role); role.CreateUserId = CurrentSession.UserId; role.CreateTime = DateTime.Now; services.Insert(role); string[] permissionIds = input.GetPermissionIds(); List <Sys_RoleAuthorize> roleAuthorizeEntitys = CreateRoleAuthorizes(role.Id, permissionIds); foreach (var roleAuthorizeEntity in roleAuthorizeEntitys) { services.Insert(roleAuthorizeEntity); } return(AddSuccessMsg()); }
public void Add(AddRoleInput input) { input.Validate(); Sys_Role role = this.CreateEntity <Sys_Role>(); AceMapper.Map(input, role); string[] permissionIds = input.GetPermissionIds(); List <Sys_RoleAuthorize> roleAuthorizeEntitys = this.CreateRoleAuthorizes(role.Id, permissionIds); this.DbContext.DoWithTransaction(() => { this.DbContext.Insert(role); foreach (var roleAuthorizeEntity in roleAuthorizeEntitys) { this.DbContext.Insert(roleAuthorizeEntity); } }); }
//[ValidateAntiForgeryToken] public ActionResult Update(UpdateRoleInput input) { input.Validate(); var services = CreateService <IAccountAppService>(); Sys_Role role = services.GetById <Sys_Role>(input.Id); role.NotNull("角色不存在"); AceMapper.Map(input, role); string[] permissionIds = input.GetPermissionIds(); List <Sys_RoleAuthorize> roleAuthorizeEntitys = CreateRoleAuthorizes(role.Id, permissionIds); role.LastModifyTime = DateTime.Now; role.LastModifyUserId = CurrentSession.UserId; services.Update(role); services.DeleteSys_RoleAuthorize(role.Id); foreach (var roleAuthorizeEntity in roleAuthorizeEntitys) { services.Insert(roleAuthorizeEntity); } return(UpdateSuccessMsg()); }