private void CreateHostRoleAndUsers() { //Admin role for host var adminRoleForHost = _context.Roles.FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin); if (adminRoleForHost == null) { adminRoleForHost = _context.Roles.Add(new Role { Name = StaticRoleNames.Host.Admin, DisplayName = StaticRoleNames.Host.Admin, IsStatic = true }); _context.SaveChanges(); //Grant all tenant permissions var permissions = PermissionFinder .GetAllPermissions(new WeChatAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host)) .ToList(); foreach (var permission in permissions) { _context.Permissions.Add( new RolePermissionSetting { Name = permission.Name, IsGranted = true, RoleId = adminRoleForHost.Id }); } _context.SaveChanges(); } //Admin user for tenancy host var adminUserForHost = _context.Users.FirstOrDefault(u => u.TenantId == null && u.UserName == User.AdminUserName); if (adminUserForHost == null) { adminUserForHost = _context.Users.Add( new User { UserName = User.AdminUserName, Name = "System", Surname = "Administrator", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, Password = new PasswordHasher().HashPassword(User.DefaultPassword) }); _context.SaveChanges(); _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id)); _context.SaveChanges(); } }
private void CreateRolesAndUsers() { //Admin role var adminRole = _context.Roles.FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin); if (adminRole == null) { adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true }); _context.SaveChanges(); //Grant all permissions to admin role var permissions = PermissionFinder .GetAllPermissions(new WeChatAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant)) .ToList(); foreach (var permission in permissions) { _context.Permissions.Add( new RolePermissionSetting { TenantId = _tenantId, Name = permission.Name, IsGranted = true, RoleId = adminRole.Id }); } _context.SaveChanges(); } //admin user var adminUser = _context.Users.FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == User.AdminUserName); if (adminUser == null) { adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**", "123qwe"); adminUser.IsEmailConfirmed = true; adminUser.IsActive = true; _context.Users.Add(adminUser); _context.SaveChanges(); //Assign Admin role to admin user _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id)); _context.SaveChanges(); } }
public ActionResult Create([Bind(Include = "Id,Published,Title,Description,PicUrl,Url,Tags")] Article article) { if (ModelState.IsValid) { article.Id = Guid.NewGuid(); db.Articles.Add(article); db.SaveChanges(); return(View("CreateSucceed")); } return(View(article)); }
private void CreateEditions() { var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition == null) { defaultEdition = new Edition { Name = EditionManager.DefaultEditionName, DisplayName = EditionManager.DefaultEditionName }; _context.Editions.Add(defaultEdition); _context.SaveChanges(); /* Add desired features to the standard edition, if wanted... */ } }
public static string GetAccessToken() { string newAccessToken = String.Empty; int weChatExpiresIn = 0; using (WeChatDbContext entity = new WeChatDbContext()) { var accesstoken = (from item in entity.AccessTokens orderby item.AccessTokenId descending select item).FirstOrDefault(); if (accesstoken == null) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); AccessToken at = new AccessToken(); at.AccessTokenStr = newAccessToken; at.ExpiresIn = weChatExpiresIn; at.LastUpdateTime = DateTime.Now; entity.AccessTokens.Add(at); entity.SaveChanges(); } else { newAccessToken = accesstoken.AccessTokenStr; TimeSpan expires_in = DateTime.Now - accesstoken.LastUpdateTime; if ((expires_in.TotalMinutes * 60) > (accesstoken.ExpiresIn - 100)) { WebClient wc = new WebClient(); byte[] data = null; data = wc.DownloadData(String.Format(WeChatWebAPI.GetAccessToken, appId, appSecret)); string strWebData = Encoding.Default.GetString(data); var accessTokenModel = (JObject)JsonConvert.DeserializeObject(strWebData); newAccessToken = accessTokenModel["access_token"].ToString(); weChatExpiresIn = Int32.Parse(accessTokenModel["expires_in"].ToString()); entity.Entry(accesstoken).State = System.Data.Entity.EntityState.Modified; accesstoken.AccessTokenStr = newAccessToken; accesstoken.ExpiresIn = weChatExpiresIn; accesstoken.LastUpdateTime = DateTime.Now; entity.SaveChanges(); } } } return newAccessToken; }
public static void UpdateUser(WeChatUser user) { using (WeChatDbContext entity = new WeChatDbContext()) { var weChatUser = (from item in entity.WeChatUsers where item.OpenId == user.OpenId orderby item.WeChatUserId descending select item).FirstOrDefault(); if (weChatUser != null) { entity.Entry(weChatUser).State = System.Data.Entity.EntityState.Modified; weChatUser.Subscribe = user.Subscribe; weChatUser.LastUpdateStateTime = DateTime.Now; if (user.Subscribe == 1) { weChatUser.City = user.City; weChatUser.Country = user.Country; weChatUser.HeadImgUrl = user.HeadImgUrl; weChatUser.Language = user.Language; weChatUser.NickName = user.NickName; weChatUser.Province = user.Province; weChatUser.LastSubscribeChannel = user.LastSubscribeChannel; weChatUser.Sex = user.Sex; } entity.SaveChanges(); } } }
public static void InsertUserSubcribeLog(UserSubscribeLog userlog) { using (WeChatDbContext entity = new WeChatDbContext()) { entity.UserSubscribeLogs.Add(userlog); entity.SaveChanges(); } }
public void Create() { new DefaultEditionCreator(_context).Create(); new DefaultLanguagesCreator(_context).Create(); new HostRoleAndUserCreator(_context).Create(); new DefaultSettingsCreator(_context).Create(); _context.SaveChanges(); }
private void AddSettingIfNotExists(string name, string value, int?tenantId = null) { if (_context.Settings.Any(s => s.Name == name && s.TenantId == tenantId && s.UserId == null)) { return; } _context.Settings.Add(new Setting(tenantId, null, name, value)); _context.SaveChanges(); }
private void AddLanguageIfNotExists(ApplicationLanguage language) { if (_context.Languages.IgnoreQueryFilters().Any(l => l.TenantId == language.TenantId && l.Name == language.Name)) { return; } _context.Languages.Add(language); _context.SaveChanges(); }
private void CreateUserAndRoles() { //Default tenant var defaultTenant = _context.Tenants.FirstOrDefault(t => t.TenancyName == Tenant.DefaultTenantName); if (defaultTenant == null) { _context.Tenants.Add(new Tenant { TenancyName = Tenant.DefaultTenantName, Name = Tenant.DefaultTenantName }); _context.SaveChanges(); } }
public static void InsertNewSubscribeUser(WeChatUser user) { using (WeChatDbContext entity = new WeChatDbContext()) { var olduser = (from item in entity.WeChatUsers where item.OpenId == user.OpenId select item).SingleOrDefault(); if (olduser == null) { entity.WeChatUsers.Add(user); entity.SaveChanges(); } else { UpdateUser(user); } } }
private void CreateDefaultTenant() { // Default tenant var defaultTenant = _context.Tenants.IgnoreQueryFilters().FirstOrDefault(t => t.TenancyName == AbpTenantBase.DefaultTenantName); if (defaultTenant == null) { defaultTenant = new Tenant(AbpTenantBase.DefaultTenantName, AbpTenantBase.DefaultTenantName); var defaultEdition = _context.Editions.IgnoreQueryFilters().FirstOrDefault(e => e.Name == EditionManager.DefaultEditionName); if (defaultEdition != null) { defaultTenant.EditionId = defaultEdition.Id; } _context.Tenants.Add(defaultTenant); _context.SaveChanges(); } }
public static void EditCodeChannel(ActivityChannels c) { using (WeChatDbContext entity = new WeChatDbContext()) { var channel = (from item in entity.ActivityChannels where item.ActivityChannelsId == c.ActivityChannelsId select item).SingleOrDefault(); if (channel != null) { entity.Entry(channel).State = System.Data.Entity.EntityState.Modified; channel.ChannelName = c.ChannelName; channel.ChannelUrl = c.ChannelUrl; channel.KeyWords = c.KeyWords; entity.SaveChanges(); } } }
public static void AddQRCode(QRCode qrcode) { using (WeChatDbContext entity = new WeChatDbContext()) { var q = (from item in entity.QRCodes where (item.QRCodeType == qrcode.QRCodeType) && (item.Title == qrcode.Title) select item).SingleOrDefault(); if (q == null) { entity.QRCodes.Add(qrcode); entity.SaveChanges(); } } }
public static void InsertNewSysWorkOrder(SysWorkOrder order, SysWorkOrderLog orderLog) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldorder = (from item in entity.SysWorkOrder where item.SysWorkOrderId == order.SysWorkOrderId select item).SingleOrDefault(); if (oldorder == null) { var tempOrder = entity.SysWorkOrder.Add(order); entity.SaveChanges(); orderLog.SysWorkOrderId = tempOrder.SysWorkOrderId; entity.SysWorkOrderLog.Add(orderLog); entity.SaveChanges(); } } }
public static void AddMenu(Menu m) { using (WeChatDbContext entity = new WeChatDbContext()) { var menu = (from item in entity.Menus where (item.Title == m.Title) && (item.MenuValue == m.MenuValue) select item).SingleOrDefault(); if (menu == null) { entity.Menus.Add(m); entity.SaveChanges(); } } }
public static void EditMenu(Menu m) { using (WeChatDbContext entity = new WeChatDbContext()) { var menu = (from item in entity.Menus where m.MenuId == item.MenuId select item).SingleOrDefault(); if (menu != null) { entity.Entry(menu).State = System.Data.Entity.EntityState.Modified; menu.MenuType = m.MenuType; menu.MenuValue = m.MenuValue; menu.ParentMenuId = m.ParentMenuId; menu.Title = m.Title; entity.SaveChanges(); } } }
public static void EditMessage(Message m) { using (WeChatDbContext entity = new WeChatDbContext()) { var menu = (from item in entity.Messages where item.MessageId == m.MessageId select item).SingleOrDefault(); if (menu != null) { entity.Entry(menu).State = System.Data.Entity.EntityState.Modified; menu.MessageUrl = m.MessageUrl; menu.Title = m.Title; menu.Key = m.Key; menu.ImageUrl = m.ImageUrl; menu.Content = m.Content; entity.SaveChanges(); } } }
public static void AddKeyword(KeyWord keyword) { using (WeChatDbContext entity = new WeChatDbContext()) { entity.KeyWords.Add(keyword); entity.SaveChanges(); } }
public static string DelKeyWord(int keywordid) { using (WeChatDbContext entity = new WeChatDbContext()) { var msg = (from item in entity.KeyWords where item.KeyWordId == keywordid select item).SingleOrDefault(); if (msg != null) { entity.KeyWords.Remove(msg); entity.SaveChanges(); return "success"; } return "error"; } }
public static string BindStaffOpenId(string cellphone, string password, string openid) { using (WeChatDbContext entity = new WeChatDbContext()) { var staff = (from item in entity.Staffs where (item.CellPhone == cellphone) && (item.Password == password) select item).SingleOrDefault(); if (staff != null) { entity.Entry(staff).State = System.Data.Entity.EntityState.Modified; staff.OpenId = openid; entity.SaveChanges(); return "success"; } return "error"; } }
public static string DelStaff(int staffid) { using (WeChatDbContext entity = new WeChatDbContext()) { var msg = (from item in entity.Staffs where item.StaffId == staffid select item).SingleOrDefault(); if (msg != null) { entity.Staffs.Remove(msg); entity.SaveChanges(); return "success"; } return "error"; } }
public static void EditStaff(Staff staff) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldStaff = (from item in entity.Staffs where (item.StaffId == staff.StaffId) && (item.CellPhone == staff.CellPhone) select item).FirstOrDefault(); if (oldStaff != null) { entity.Entry(oldStaff).State = System.Data.Entity.EntityState.Modified; oldStaff.LastUpdateTime = DateTime.Now; oldStaff.CellPhone = staff.CellPhone; oldStaff.IsEnabled = staff.IsEnabled; oldStaff.Name = staff.Name; if (staff.Password != "") { oldStaff.Password = staff.Password; } oldStaff.StaffType = staff.StaffType; entity.SaveChanges(); } } }
public static void AddStaff(Staff staff) { using (WeChatDbContext entity = new WeChatDbContext()) { entity.Staffs.Add(staff); entity.SaveChanges(); } }
public static void CancelOrder(int orderid, int userid, string username) { using (WeChatDbContext entity = new WeChatDbContext()) { var order = (from item in entity.SysWorkOrder where item.SysWorkOrderId == orderid select item).SingleOrDefault(); if (order != null) { entity.Entry(order).State = System.Data.Entity.EntityState.Modified; order.CurrentStatus = "qx"; SysWorkOrderLog wol = new SysWorkOrderLog(); wol.CreateTime = DateTime.Now; wol.Description = "操作人:" + username + ",取消了保修请求"; wol.OperateUserId = userid; wol.SysWorkOrderId = orderid; entity.SysWorkOrderLog.Add(wol); entity.SaveChanges(); } } }
public static void AddMessage(Message m) { using (WeChatDbContext entity = new WeChatDbContext()) { entity.Messages.Add(m); entity.SaveChanges(); } }
public static void UpdateSysWorkOrder(SysWorkOrder order, SysWorkOrderLog orderLog) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldorder = (from item in entity.SysWorkOrder where item.SysWorkOrderId == order.SysWorkOrderId select item).SingleOrDefault(); if (oldorder != null) { entity.Entry(oldorder).State = System.Data.Entity.EntityState.Modified; oldorder.OrderTitle = order.OrderTitle; oldorder.LastUpdateTime = DateTime.Now; oldorder.Device = order.Device; oldorder.DeviceCode = order.DeviceCode; oldorder.Description = order.Description; oldorder.Department = order.Department; oldorder.CurrentStatus = order.CurrentStatus; oldorder.LastUpdateUserId = order.LastUpdateUserId; entity.SysWorkOrderLog.Add(orderLog); entity.SaveChanges(); } } }
private void CreateHostRoleAndUsers() { // Admin role for host var adminRoleForHost = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == null && r.Name == StaticRoleNames.Host.Admin); if (adminRoleForHost == null) { adminRoleForHost = _context.Roles.Add(new Role(null, StaticRoleNames.Host.Admin, StaticRoleNames.Host.Admin) { IsStatic = true, IsDefault = true }).Entity; _context.SaveChanges(); } // Grant all permissions to admin role for host var grantedPermissions = _context.Permissions.IgnoreQueryFilters() .OfType <RolePermissionSetting>() .Where(p => p.TenantId == null && p.RoleId == adminRoleForHost.Id) .Select(p => p.Name) .ToList(); var permissions = PermissionFinder .GetAllPermissions(new WeChatAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Host) && !grantedPermissions.Contains(p.Name)) .ToList(); if (permissions.Any()) { _context.Permissions.AddRange( permissions.Select(permission => new RolePermissionSetting { TenantId = null, Name = permission.Name, IsGranted = true, RoleId = adminRoleForHost.Id }) ); _context.SaveChanges(); } // Admin user for host var adminUserForHost = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == null && u.UserName == AbpUserBase.AdminUserName); if (adminUserForHost == null) { var user = new User { TenantId = null, UserName = AbpUserBase.AdminUserName, Name = "admin", Surname = "admin", EmailAddress = "*****@*****.**", IsEmailConfirmed = true, IsActive = true }; user.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(user, "123qwe"); user.SetNormalizedNames(); adminUserForHost = _context.Users.Add(user).Entity; _context.SaveChanges(); // Assign Admin role to admin user _context.UserRoles.Add(new UserRole(null, adminUserForHost.Id, adminRoleForHost.Id)); _context.SaveChanges(); // User account of admin user _context.UserAccounts.Add(new UserAccount { TenantId = null, UserId = adminUserForHost.Id, UserName = AbpUserBase.AdminUserName, EmailAddress = adminUserForHost.EmailAddress }); _context.SaveChanges(); } }
public static string InsertUserMessage(UserMessage message) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldmsg = (from item in entity.UserMessages where item.MsgId == message.MsgId select item).SingleOrDefault(); if (oldmsg == null) { message.CreateTime = DateTime.Now; message.UpdateTime = DateTime.Now; entity.UserMessages.Add(message); entity.SaveChanges(); } return ""; } }
public static string DelMenu(int menuid) { using (WeChatDbContext entity = new WeChatDbContext()) { var delmenu = (from item in entity.Menus where (item.MenuId == menuid) || (item.ParentMenuId == menuid) select item).ToList(); entity.Menus.RemoveRange(delmenu); entity.SaveChanges(); var content = PostMenuToWeChat(); string returnresult = content.SelectToken("errmsg").ToString(); return returnresult; } }
public static void UpdateCouponCustomerInfo(ActivityModels am) { using (WeChatDbContext entity = new WeChatDbContext()) { var coupon = (from item in entity.ActivityModels where item.CouponCode == am.CouponCode select item).SingleOrDefault(); if (coupon != null) { entity.Entry(coupon).State = System.Data.Entity.EntityState.Modified; coupon.ActivityName = am.ActivityName; coupon.CellPhone = am.CellPhone; coupon.CustomerName = am.CustomerName; coupon.Description = am.Description; coupon.IsCancel = am.IsCancel; coupon.IsRevisited = am.IsRevisited; coupon.IsUsed = am.IsUsed; entity.SaveChanges(); } } }
private void CreateRolesAndUsers() { // Admin role var adminRole = _context.Roles.IgnoreQueryFilters().FirstOrDefault(r => r.TenantId == _tenantId && r.Name == StaticRoleNames.Tenants.Admin); if (adminRole == null) { adminRole = _context.Roles.Add(new Role(_tenantId, StaticRoleNames.Tenants.Admin, StaticRoleNames.Tenants.Admin) { IsStatic = true }).Entity; _context.SaveChanges(); } // Grant all permissions to admin role var grantedPermissions = _context.Permissions.IgnoreQueryFilters() .OfType <RolePermissionSetting>() .Where(p => p.TenantId == _tenantId && p.RoleId == adminRole.Id) .Select(p => p.Name) .ToList(); var permissions = PermissionFinder .GetAllPermissions(new WeChatAuthorizationProvider()) .Where(p => p.MultiTenancySides.HasFlag(MultiTenancySides.Tenant) && !grantedPermissions.Contains(p.Name)) .ToList(); if (permissions.Any()) { _context.Permissions.AddRange( permissions.Select(permission => new RolePermissionSetting { TenantId = _tenantId, Name = permission.Name, IsGranted = true, RoleId = adminRole.Id }) ); _context.SaveChanges(); } // Admin user var adminUser = _context.Users.IgnoreQueryFilters().FirstOrDefault(u => u.TenantId == _tenantId && u.UserName == AbpUserBase.AdminUserName); if (adminUser == null) { adminUser = User.CreateTenantAdminUser(_tenantId, "*****@*****.**"); adminUser.Password = new PasswordHasher <User>(new OptionsWrapper <PasswordHasherOptions>(new PasswordHasherOptions())).HashPassword(adminUser, "123qwe"); adminUser.IsEmailConfirmed = true; adminUser.IsActive = true; _context.Users.Add(adminUser); _context.SaveChanges(); // Assign Admin role to admin user _context.UserRoles.Add(new UserRole(_tenantId, adminUser.Id, adminRole.Id)); _context.SaveChanges(); // User account of admin user if (_tenantId == 1) { _context.UserAccounts.Add(new UserAccount { TenantId = _tenantId, UserId = adminUser.Id, UserName = AbpUserBase.AdminUserName, EmailAddress = adminUser.EmailAddress }); _context.SaveChanges(); } } }
public static void InsertActivityCode(ActivityModels codeModel) { using (WeChatDbContext entity = new WeChatDbContext()) { //var coupon = (from item in entity.ActivityModels select item).SingleOrDefault(); entity.ActivityModels.Add(codeModel); entity.SaveChanges(); } }
public static void InsertActivityCodeList(List<ActivityModels> codeList) { using (WeChatDbContext entity = new WeChatDbContext()) { //var coupon = (from item in entity.ActivityModels select item).SingleOrDefault(); foreach (var code in codeList) { entity.ActivityModels.Add(code); } entity.SaveChanges(); } }
public static void AddCodeChannel(ActivityChannels c) { using (WeChatDbContext entity = new WeChatDbContext()) { var channel = (from item in entity.ActivityChannels where (item.ChannelName == c.ChannelName) && (item.ChannelUrl == c.ChannelUrl) select item).SingleOrDefault(); if (channel == null) { entity.ActivityChannels.Add(c); entity.SaveChanges(); } } }
public static void EditKeyword(KeyWord keyword) { using (WeChatDbContext entity = new WeChatDbContext()) { var oldKeyword = (from item in entity.KeyWords where item.KeyWordId == keyword.KeyWordId select item).SingleOrDefault(); if (oldKeyword != null) { entity.Entry(oldKeyword).State = System.Data.Entity.EntityState.Modified; oldKeyword.Title = keyword.Title; oldKeyword.ResultUrl = keyword.ResultUrl; oldKeyword.MsgKeyValue = keyword.MsgKeyValue; oldKeyword.LastUpdateTime = DateTime.Now; oldKeyword.Content = keyword.Content; entity.SaveChanges(); } } }
public static void EditQRCode(QRCode qrcode) { using (WeChatDbContext entity = new WeChatDbContext()) { var q = (from item in entity.QRCodes where item.QRCodeId == qrcode.QRCodeId select item).SingleOrDefault(); if (q != null) { entity.Entry(q).State = System.Data.Entity.EntityState.Modified; q.Title = qrcode.Title; q.LastUpdateTime = DateTime.Now; entity.SaveChanges(); } } }