static BBaseManager() { using (KuanMaiEntities db = new KuanMaiEntities()) { Areas = (from area in db.Common_District select area).ToList <Common_District>(); } }
public bool VerifyPassword(string password, int uid = 0) { bool result = false; int user_id = this.CurrentUser.ID; if (uid > 0) { user_id = uid; } using (KuanMaiEntities db = new KuanMaiEntities()) { User user = (from u in db.User where u.User_ID == user_id && u.IsSystemUser == true select u).FirstOrDefault <User>(); if (user == null) { throw new KMJXCException("用户不存在"); } if (Encrypt.MD5(password) == user.Password) { result = true; } } return(result); }
private void InitializeUser(int uid) { using (KuanMaiEntities db = new KuanMaiEntities()) { this.CurrentUser = (from u in db.User where u.User_ID == uid && u.IsSystemUser == true select new BSysUser { ID = u.User_ID, Name = u.Name, Created = (long)u.Created, Modified = (long)u.Modified, NickName = u.NickName }).FirstOrDefault <BSysUser>(); PermissionManager pManager = new PermissionManager(); Admin_Super adminUser = (from a in db.Admin_Super where a.user_id == this.CurrentUser.ID select a).FirstOrDefault <Admin_Super>(); if (adminUser != null) { this.CurrentUser.Permission = pManager.GetAllPermission(); } else { this.CurrentUser.Permission = pManager.GetUserPermission(new BUser { ID = this.CurrentUser.ID }); } } }
public void UpdateStatus(int bug_id, int status) { using (KuanMaiEntities db = new KuanMaiEntities()) { Bug bug = (from b in db.Bug where b.ID == bug_id select b).FirstOrDefault <Bug>(); if (bug == null) { throw new KMJXCException("编号为:" + bug_id + " 的问题不存在"); } Bug_Status dbStatus = (from s in db.Bug_Status where s.ID == status select s).FirstOrDefault <Bug_Status>(); if (dbStatus == null) { throw new KMJXCException("状态数据:" + status + " 为无效数据"); } if (bug.Status == status) { throw new KMJXCException("当前的状态为:" + dbStatus.Status + ", 选择其他状态进行设置"); } bug.Status = status; db.SaveChanges(); } }
/// <summary> /// Create new supplier /// </summary> /// <param name="supplier"></param> /// <returns></returns> public bool CreateSupplier(Supplier supplier) { bool result = false; if (this.CurrentUserPermission.ADD_SUPPLIER == 0) { throw new KMJXCException("没有权限添加新供应商"); } if (string.IsNullOrEmpty(supplier.Name)) { throw new KMJXCException("供应商名称不能为空"); } if (supplier.User_ID == 0 && this.CurrentUser != null) { supplier.User_ID = this.CurrentUser.ID; } using (KuanMaiEntities db = new KuanMaiEntities()) { var obj = (from sp in db.Supplier where (sp.Shop_ID == this.Shop.Shop_ID || sp.Shop_ID == this.Main_Shop.Shop_ID) && supplier.Name.Contains(sp.Name) select sp); if (obj.ToList <Supplier>().Count > 0) { throw new KMJXCException("供应商名称已经存在"); } db.Supplier.Add(supplier); db.SaveChanges(); result = true; } return(result); }
/// <summary> /// Set product supplier /// </summary> /// <param name="product_id">Product ID</param> /// <param name="supplier_id">Supplier ID</param> /// <returns>TRUE/FALSE</returns> public bool SetProductSupplier(int product_id, int supplier_id) { bool result = false; if (this.CurrentUserPermission.ADD_SUPPLIER == 0) { throw new KMJXCException("没有创建供应商的权限"); } if (product_id == 0 || supplier_id == 0) { throw new KMJXCException("创建产品供应商时,产品和供应商都必须选择"); } using (KuanMaiEntities db = new KuanMaiEntities()) { Product_Supplier pps = (from p in db.Product_Supplier where p.Product_ID == product_id && p.Supplier_ID == supplier_id select p).FirstOrDefault <Product_Supplier>(); if (pps != null) { throw new KMJXCException(""); } Product_Supplier ps = new Product_Supplier(); ps.Product_ID = product_id; ps.Supplier_ID = supplier_id; db.Product_Supplier.Add(ps); db.SaveChanges(); result = true; } return(result); }
/// <summary> /// Add properties for parent product or child product /// </summary> /// <param name="product_id"></param> /// <param name="props"></param> /// <returns></returns> public bool AddProductProperties(int product_id, List <BProductProperty> props) { Product dbProduct = this.GetProduct(product_id); if (dbProduct == null) { throw new KMJXCException("产品不存在"); } using (KuanMaiEntities db = new KuanMaiEntities()) { if (props != null && props.Count > 0) { List <Product_Specifications> specs = (from ps in db.Product_Specifications where ps.Product_ID == dbProduct.Product_ID select ps).ToList <Product_Specifications>(); foreach (BProductProperty prop in props) { Product_Specifications ps = (from sp in specs where sp.Product_Spec_ID == prop.PID && sp.Product_Spec_Value_ID == prop.PVID && sp.Product_ID == product_id select sp).FirstOrDefault <Product_Specifications>(); if (ps == null) { ps = new Product_Specifications(); ps.Product_Spec_Value_ID = prop.PVID; ps.Product_Spec_ID = prop.PID; ps.Product_ID = product_id; db.Product_Specifications.Add(ps); } } db.SaveChanges(); } } return(true); }
/// <summary> /// Update mall name or description /// </summary> /// <param name="mall"></param> /// <returns></returns> public bool UpdateMall(Mall_Type mall) { bool result = false; Mall_Type mall_type = null; using (KuanMaiEntities db = new KuanMaiEntities()) { if (mall.Mall_Type_ID > 0) { mall_type = this.GetMallDetail(mall.Mall_Type_ID); } else if (!string.IsNullOrEmpty(mall.Name)) { mall_type = this.GetMallDetail(mall.Name); } if (mall_type != null) { db.Mall_Type.Attach(mall_type); mall_type.Name = mall.Name; mall_type.Description = mall.Description; db.SaveChanges(); result = true; } } return(result); }
/// <summary> /// Update access token in local db /// </summary> /// <param name="token"></param> /// <returns></returns> private bool UpdateLocalAccessToken(Access_Token token) { bool result = false; Access_Token local_token = null; KuanMaiEntities db = new KuanMaiEntities(); var etoken = from p in db.Access_Token where p.Mall_Type_ID == token.Mall_Type_ID && p.User_ID == token.User_ID select p; if (etoken != null) { local_token = etoken.ToList <Access_Token>()[0]; } if (local_token != null) { local_token.Access_Token1 = token.Access_Token1; local_token.Expirse_In = token.Expirse_In; local_token.Request_Time = token.Request_Time; local_token.RExpirse_In = token.RExpirse_In; db.Access_Token.Attach(local_token); db.SaveChanges(); result = true; } return(result); }
/// <summary> /// /// </summary> /// <param name="bug"></param> /// <returns></returns> public bool CreateNewBug(BBug bug) { if (bug.Created_By == null) { throw new KMJXCException("创建Bug时必须有创建人"); } bool result = false; using (KuanMaiEntities db = new KuanMaiEntities()) { Bug dbBug = new Bug(); dbBug.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); if (bug.Created_By != null) { dbBug.Created_By = bug.Created_By.ID; } dbBug.Description = bug.Description; if (bug.Feature != null) { dbBug.Feature = bug.Feature.ID; } dbBug.Function = 0; dbBug.Modified = dbBug.Created; dbBug.Modified_By = dbBug.Created_By; dbBug.Resolved = 0; dbBug.Resolved_By = 0; dbBug.Status = 1; dbBug.Title = bug.Title; db.Bug.Add(dbBug); db.SaveChanges(); result = true; } return(result); }
/// <summary> /// /// </summary> protected virtual void GetUserPermission() { if (this.CurrentUser == null || this.CurrentUser.ID <= 0) { return; //throw new KMJXCException("调用 " + this.GetType() + " 没有传入当前登录用户对象", ExceptionLevel.SYSTEM); } if (this.CurrentUserPermission == null) { CurrentUserPermission = this.permissionManager.GetUserPermission(this.CurrentUser); } if (this.CurrentUser.ID == this.Shop.User_ID) { //shop owner has full permissions Type permission = typeof(Permission); FieldInfo[] fields = permission.GetFields(); foreach (FieldInfo field in fields) { field.SetValue(CurrentUserPermission, 1); } } using (KuanMaiEntities db = new KuanMaiEntities()) { this.AccessToken = (from at in db.Access_Token where at.User_ID == this.CurrentUser.ID select at).FirstOrDefault <Access_Token>(); } }
/// <summary> /// /// </summary> /// <param name="user_id"></param> /// <param name="shop_id"></param> /// <returns></returns> public List <BAdminRole> GetUserAdminRoles(int user_id, int shop_id = 0) { if (this.CurrentUserPermission.VIEW_USER_PERMISSION == 0) { throw new KMJXCException("没有权限查看用户权限"); } int shopId = this.Shop.Shop_ID; if (shop_id > 0) { shopId = shop_id; } List <BAdminRole> roles = new List <BAdminRole>(); using (KuanMaiEntities db = new KuanMaiEntities()) { List <Admin_Action> allActions = (from action in db.Admin_Action select action).ToList <Admin_Action>(); int[] role_ids = (from role in db.Admin_Role where role.shop_id == shopId && role.enabled == true select role.id).ToArray <int>(); List <Admin_Role_Action> role_Actions = (from roleAction in db.Admin_Role_Action where role_ids.Contains(roleAction.role_id) select roleAction).ToList <Admin_Role_Action>(); var tmp = from user_role in db.Admin_User_Role where user_role.user_id == user_id join role in db.Admin_Role on user_role.role_id equals role.id into lRole from l_role in lRole.DefaultIfEmpty() join shop in db.Shop on l_role.shop_id equals shop.Shop_ID into lShop from l_shop in lShop.DefaultIfEmpty() select new BAdminRole { ID = user_role.role_id, Name = l_role.role_name, Description = l_role.description, Shop = new BShop { ID = l_shop.Shop_ID, Title = l_shop.Name } }; roles = tmp.ToList <BAdminRole>(); foreach (BAdminRole role in roles) { var actions = from action in role_Actions where action.role_id == role.ID join action1 in allActions on action.action_id equals action1.id into lAction1 from l_action1 in lAction1.DefaultIfEmpty() select new BAdminAction { ActionName = l_action1.action_name, Description = l_action1.action_description, ID = action.action_id }; role.Actions = actions.ToList <BAdminAction>(); } } return(roles); }
/// <summary> /// /// </summary> /// <param name="productId"></param> /// <returns></returns> public List <BProduct> GetProductProperties(int productId) { List <BProduct> props = null; using (KuanMaiEntities db = new KuanMaiEntities()) { Product product = (from p in db.Product where p.Product_ID == productId select p).FirstOrDefault <Product>(); if (product == null) { throw new KMJXCException("编号为:" + productId + " 的产品不存在"); } var mall_id = from m in db.Mall_Product where m.Outer_ID == productId select m.Mall_ID; var children_id = from sku in db.Mall_Product_Sku where mall_id.Contains(sku.Mall_ID) && sku.Outer_ID > 0 select sku.Outer_ID; props = (from p in db.Product where p.Parent_ID == productId && !children_id.Contains(p.Product_ID) select new BProduct { ID = p.Product_ID, Title = p.Name }).ToList <BProduct>(); if (props == null || props.Count <= 0) { throw new KMJXCException("编号为:" + productId + " 的产品不存在未关联的销售属性,请先编辑产品添加属性"); } int[] tmpProducts = (from p in props select p.ID).ToArray <int>(); List <BProductProperty> properties = new List <BProductProperty>(); properties = (from pv in db.Product_Specifications join prop in db.Product_Spec on pv.Product_Spec_ID equals prop.Product_Spec_ID into LProp from l_prop in LProp.DefaultIfEmpty() join propV in db.Product_Spec_Value on pv.Product_Spec_Value_ID equals propV.Product_Spec_Value_ID into LPropv from l_propv in LPropv.DefaultIfEmpty() where tmpProducts.Contains(pv.Product_ID) select new BProductProperty { PID = pv.Product_Spec_ID, PName = l_prop.Name, ProductID = pv.Product_ID, PValue = l_propv.Name, PVID = pv.Product_Spec_Value_ID }).OrderBy(p => p.PID).ToList <BProductProperty>(); foreach (BProduct prop in props) { prop.Properties = (from prp in properties where prp.ProductID == prop.ID select prp).ToList <BProductProperty>(); } } return(props); }
/// <summary> /// Get all actions by category /// </summary> /// <param name="role_id"></param> /// <returns></returns> public List <BAdminCategoryAction> GetActionsByCategory(int role_id = 0) { List <BAdminCategoryAction> actions = new List <BAdminCategoryAction>(); using (KuanMaiEntities db = new KuanMaiEntities()) { List <Admin_Action> roleActions = new List <Admin_Action>(); if (role_id > 0) { var tmp = from roleA in db.Admin_Role_Action where roleA.role_id == role_id join action in db.Admin_Action on roleA.action_id equals action.id into lAction from l_action in lAction.DefaultIfEmpty() select l_action; roleActions = (from action in tmp where action.enable == true select action).ToList <Admin_Action>(); } List <BAdminCategory> categories = (from category in db.Admin_Category select new BAdminCategory { ID = category.ID, Created = category.Created, Name = category.Name }).ToList <BAdminCategory>(); foreach (BAdminCategory category in categories) { BAdminCategoryAction cateAction = new BAdminCategoryAction(); cateAction.Category = category; cateAction.Actions = (from action in db.Admin_Action where action.category_id == category.ID && action.enable == true select new BAdminAction { ActionName = action.action_name, Description = action.action_description, ID = action.id, Enabled = action.enable }).ToList <BAdminAction>(); foreach (BAdminAction bAction in cateAction.Actions) { Admin_Action dbAction = (from action in roleActions where action.id == bAction.ID select action).FirstOrDefault <Admin_Action>(); if (dbAction != null) { bAction.HasPermission = true; } } actions.Add(cateAction); } } return(actions); }
/// <summary> /// /// </summary> /// <returns></returns> public List <Express> GetExpresses() { List <Express> expresses = new List <Express>(); using (KuanMaiEntities db = new KuanMaiEntities()) { expresses = (from express in db.Express orderby express.Express_ID ascending select express).ToList <Express>(); } return(expresses); }
/// <summary> /// /// </summary> /// <returns></returns> public Corp_Info GetCorpInfo() { Corp_Info info = null; using (KuanMaiEntities db = new KuanMaiEntities()) { info = (from ci in db.Corp_Info where ci.IsCurrent == true select ci).FirstOrDefault <Corp_Info>(); } return(info); }
/// <summary> /// /// </summary> /// <param name="user_id"></param> /// <returns></returns> public Employee GetEmployInfo(int user_id) { Employee e = null; using (KuanMaiEntities db = new KuanMaiEntities()) { e = (from em in db.Employee where em.User_ID == user_id select em).FirstOrDefault <Employee>(); } return(e); }
/// <summary> /// /// </summary> /// <param name="role_id"></param> /// <param name="actions"></param> public void UpdateRoleActions(int role_id, int[] actions) { if (this.CurrentUserPermission.UPDATE_ROLE_ACTION == 0) { throw new KMJXCException("没有权限执行此操作"); } using (KuanMaiEntities db = new KuanMaiEntities()) { Admin_Role role = (from r in db.Admin_Role where r.id == role_id select r).FirstOrDefault <Admin_Role>(); if (role == null) { throw new KMJXCException("此权限分组不存在,不能添加任何权限"); } List <Admin_Role_Action> role_actions = (from ra in db.Admin_Role_Action where ra.role_id == role_id select ra).ToList <Admin_Role_Action>(); List <Admin_Action> all_actions = (from action in db.Admin_Action select action).ToList <Admin_Action>(); //add new foreach (int action in actions) { Admin_Action dbAction = (from dba in all_actions where dba.id == action select dba).FirstOrDefault <Admin_Action>(); //No action if (dbAction == null) { continue; } Admin_Role_Action dbRoleAction = (from dbra in role_actions where dbra.role_id == role_id && dbra.action_id == action select dbra).FirstOrDefault <Admin_Role_Action>(); //the role already has the action if (dbRoleAction != null) { continue; } dbRoleAction = new Admin_Role_Action(); dbRoleAction.action_id = action; dbRoleAction.role_id = role_id; db.Admin_Role_Action.Add(dbRoleAction); } //remove deleted foreach (Admin_Role_Action action in role_actions) { if (!actions.Contains(action.action_id)) { db.Admin_Role_Action.Remove(action); } } db.SaveChanges(); } }
/// <summary> /// Create new user /// </summary> /// <param name="user"></param> /// <returns></returns> public BUser CreateNewUser(BUser user) { if (user == null) { throw new UserException("用户实体不能为空引用"); } if (string.IsNullOrEmpty(user.Name)) { throw new UserException("用户名不能为空"); } if (this.CurrentUserPermission.ADD_USER == 0) { throw new UserException("没有权限创建新用户"); } KuanMaiEntities dba = new KuanMaiEntities(); try { if (GetUser(user) != null) { throw new UserException("用户名已经存在"); } User dbUser = new User(); dbUser.User_ID = user.ID; dbUser.Mall_ID = user.Mall_ID; dbUser.Mall_Name = user.Mall_Name; dbUser.Name = user.Name; dbUser.Mall_Type = user.Type.ID; if (user.Parent != null) { dbUser.Parent_Mall_ID = user.Parent.Mall_ID; dbUser.Parent_Mall_Name = user.Parent.Mall_Name; dbUser.Parent_User_ID = user.Parent.ID; } dba.User.Add(dbUser); dba.SaveChanges(); return(user); } catch (Exception ex) { throw ex; } finally { if (dba != null) { dba.Dispose(); } } }
/// <summary> /// /// </summary> /// <returns></returns> public List <Open_Key> GetOpenKeys() { List <Open_Key> keys = null; using (KuanMaiEntities db = new KuanMaiEntities()) { keys = (from key in db.Open_Key select key).ToList <Open_Key>(); } return(keys); }
public List <Mall_Type> GetMallTypes() { List <Mall_Type> types = null; using (KuanMaiEntities db = new KuanMaiEntities()) { types = (from mtype in db.Mall_Type select mtype).ToList <Mall_Type>(); } return(types); }
public static void SyncUserAction() { Type action = typeof(UserLogAction); FieldInfo[] fields = action.GetFields(); if (fields == null || fields.Length <= 0) { return; } KuanMaiEntities db = new KuanMaiEntities(); try { List <User_Action> allActions = (from ac in db.User_Action select ac).ToList <User_Action>(); foreach (FieldInfo field in fields) { UserActionAttribute attr = field.GetCustomAttribute <UserActionAttribute>(); int aValue = (int)field.GetValue(null); User_Action userAc = (from ac in allActions where ac.Action_ID == aValue && ac.Action_Name == field.Name select ac).FirstOrDefault <User_Action>(); if (userAc == null) { userAc = new User_Action(); userAc.Action_ID = aValue; userAc.Action_Name = field.Name; userAc.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now); if (attr != null) { userAc.Action_Description = attr.Description; } db.User_Action.Add(userAc); } else { if (attr != null) { userAc.Action_Description = attr.Description; } } } db.SaveChanges(); } catch (Exception ex) { } finally { if (db != null) { db.Dispose(); } } }
/// <summary> /// /// </summary> /// <param name="parent_id"></param> /// <returns></returns> public List <Common_District> GetAreas(int parent_id) { List <Common_District> areas = null; using (KuanMaiEntities db = new KuanMaiEntities()) { var a = (from ass in db.Common_District where ass.upid == parent_id select ass); areas = a.ToList <Common_District>(); } return(areas); }
/// <summary> /// /// </summary> /// <param name="image"></param> /// <returns></returns> public bool CreateImage(KM.JXC.DBA.Image image) { bool result = false; using (KuanMaiEntities db = new KuanMaiEntities()) { db.Image.Add(image); db.SaveChanges(); result = true; } return(result); }
/// <summary> /// /// </summary> /// <param name="image"></param> public void UpdateImage(KM.JXC.DBA.Image image) { using (KuanMaiEntities db = new KuanMaiEntities()) { Image imge = (from img in db.Image where img.ID == image.ID select img).FirstOrDefault <Image>(); if (imge == null) { throw new KMJXCException("图片不存在"); } base.UpdateProperties(imge, image); db.SaveChanges(); } }
private void GetUser(int uid) { using (KuanMaiEntities db = new KuanMaiEntities()) { this.currentUser = (from user in db.User where user.User_ID == uid select new BUser { ID = user.User_ID, Mall_Name = user.Mall_Name, Name = user.Name }).FirstOrDefault <BUser>(); } }
/// <summary> /// Get mall object by mall name /// </summary> /// <param name="name"></param> /// <returns></returns> public Mall_Type GetMallDetail(string name) { Mall_Type mall = null; using (KuanMaiEntities db = new KuanMaiEntities()) { var mt = from malltype in db.Mall_Type where malltype.Name == name select malltype; if (mt != null) { mall = mt.ToList <Mall_Type>()[0]; } } return(mall); }
/// <summary> /// Get mall object by mall id /// </summary> /// <param name="mall_type_id"></param> /// <returns></returns> public Mall_Type GetMallDetail(long mall_type_id) { Mall_Type mall = null; using (KuanMaiEntities db = new KuanMaiEntities()) { var mt = from malltype in db.Mall_Type where malltype.Mall_Type_ID == mall_type_id select malltype; if (mt != null) { mall = mt.ToList <Mall_Type>()[0]; } } return(mall); }
/// <summary> /// Get single product in db Product struct /// </summary> /// <param name="id">Product ID</param> /// <returns>Product object</returns> private Product GetProduct(int id) { if (id == 0) { throw new KMJXCException("产品不存在"); } Product product = null; using (KuanMaiEntities db = new KuanMaiEntities()) { product = (from pdt in db.Product where pdt.Product_ID == id select pdt).FirstOrDefault <Product>(); } return(product); }
/// <summary> /// Remove supplier products /// </summary> /// <param name="product_ids"></param> /// <param name="supplier_id"></param> public void RemoveSupplierProducts(int[] product_ids, int supplier_id) { if (supplier_id <= 0) { throw new KMJXCException("更新供应商产品时必须输入供应商编号"); } if (this.CurrentUserPermission.UPDATE_SUPPLIER_PRODUCT == 0) { throw new KMJXCException("没有权限移除供应商产品"); } using (KuanMaiEntities db = new KuanMaiEntities()) { if (product_ids == null || product_ids.Length <= 0) { return; } Supplier supplier = (from s in db.Supplier where s.Supplier_ID == supplier_id select s).FirstOrDefault <Supplier>(); if (supplier == null) { throw new KMJXCException("编号为:" + supplier_id + " 的供应商信息不存在"); } if (this.Shop.Shop_ID == this.Main_Shop.Shop_ID) { int[] child_shops = (from c in this.ChildShops select c.ID).ToArray <int>(); if (this.Shop.Shop_ID != supplier.Shop_ID && !child_shops.Contains(supplier.Shop_ID)) { throw new KMJXCException("不能操作其他店铺的供应商,只能使用主店铺和子店铺的供应商"); } } else { if (supplier.Shop_ID != this.Shop.Shop_ID && supplier.Shop_ID != this.Main_Shop.Shop_ID) { throw new KMJXCException("不能操作其他店铺的供应商,只能使用主店铺和子店铺的供应商"); } } List <Product_Supplier> products = (from s in db.Product_Supplier where s.Supplier_ID == supplier_id && product_ids.Contains(s.Product_ID) select s).ToList <Product_Supplier>(); foreach (Product_Supplier ps in products) { ps.Enabled = false; } db.SaveChanges(); } }