Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        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();
            }
        }
Ejemplo n.º 4
0
        /// <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);
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
0
        /// <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();
            }
        }
Ejemplo n.º 9
0
        /// <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();
                }
            }
        }
Ejemplo n.º 10
0
        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();
                }
            }
        }
Ejemplo n.º 11
0
        /// <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);
        }
Ejemplo n.º 12
0
 /// <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();
     }
 }
Ejemplo n.º 13
0
        /// <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();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Update actions
        /// </summary>
        /// <param name="actions"></param>
        public void UpdateAction(List <Admin_Action> actions)
        {
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                foreach (Admin_Action action in actions)
                {
                    if (action.id > 0)
                    {
                        db.Admin_Action.Attach(action);
                    }
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        public void CreateActionLog(BUserActionLog action)
        {
            if (action == null || action.Shop == null)
            {
                return;
            }
            KuanMaiEntities db = null;

            try
            {
                db = new KuanMaiEntities();
                User_Action_Log log = new User_Action_Log();

                log.Action = action.Action.Action_ID;

                log.Description = action.Description;
                if (action.User != null && action.User.ID > 0)
                {
                    log.User_ID = action.User.ID;
                }
                else
                {
                    log.User_ID = this.CurrentUser.ID;
                }

                log.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                if (string.IsNullOrEmpty(log.Description))
                {
                    log.Description = "";
                }
                log.Shop_ID = action.Shop.ID;
                db.User_Action_Log.Add(log);
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
            }
            catch (Exception ex)
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image_id"></param>
        /// <returns></returns>
        public bool DeleteProductImage(int product_id)
        {
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                List <Image> images = (from img in db.Image where img.ProductID == product_id select img).ToList <Image>();

                foreach (Image img in images)
                {
                    db.Image.Remove(img);
                }
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image_id"></param>
        /// <returns></returns>
        public bool DeleteImage(int image_id, out Image image)
        {
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                image = (from img in db.Image where img.ID == image_id select img).FirstOrDefault <Image>();
                if (image == null)
                {
                    throw new KMJXCException("图片不存在");
                }

                db.Image.Remove(image);
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="propertyId"></param>
        /// <param name="value"></param>
        public void CreatePropertyValues(int propertyId, List <string> value)
        {
            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                Product_Spec ps = (from prop in db.Product_Spec where prop.Product_Spec_ID == propertyId select prop).FirstOrDefault <Product_Spec>();
                if (ps == null)
                {
                    throw new KMJXCException("属性不存在,不能添加属性值");
                }

                List <Product_Spec_Value> psValues = (from psv in db.Product_Spec_Value where psv.Product_Spec_ID == propertyId select psv).ToList <Product_Spec_Value>();

                if (value != null && value.Count > 0)
                {
                    foreach (string v in value)
                    {
                        Product_Spec_Value propValue = (from propv in psValues where propv.Name == v select propv).FirstOrDefault <Product_Spec_Value>();
                        if (propValue == null)
                        {
                            propValue = new Product_Spec_Value();
                            propValue.Product_Spec_ID = propertyId;
                            propValue.Name            = v;
                            propValue.Mall_PVID       = "";
                            propValue.Created         = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                            db.Product_Spec_Value.Add(propValue);
                        }
                    }

                    db.SaveChanges();
                }
            }
            catch
            {
            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="desc"></param>
        /// <param name="shop_id"></param>
        public BAdminRole CreateRole(string name, string desc, int[] actions, int shop_id = 0)
        {
            BAdminRole badminRole = null;

            if (this.CurrentUserPermission.ADD_ADMIN_ROLE == 0)
            {
                throw new KMJXCException("没有权限创建权限分组");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                int shop = this.Shop.Shop_ID;
                if (shop_id > 0)
                {
                    shop = shop_id;
                }
                Admin_Role admin_role = (from role in db.Admin_Role where role.shop_id == shop && role.role_name == name select role).FirstOrDefault <Admin_Role>();
                if (admin_role != null)
                {
                    throw new KMJXCException("名为 " + name + " 的分组已经存在");
                }

                admin_role             = new Admin_Role();
                admin_role.role_name   = name;
                admin_role.shop_id     = shop;
                admin_role.enabled     = true;
                admin_role.description = desc;
                admin_role.create_uid  = this.CurrentUser.ID;
                admin_role.create_date = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                admin_role.system_role = false;
                db.Admin_Role.Add(admin_role);
                db.SaveChanges();
                if (actions != null)
                {
                    this.UpdateRoleActions(admin_role.id, actions);
                }

                badminRole = new BAdminRole()
                {
                    ID = admin_role.id, Name = admin_role.role_name, Description = admin_role.description
                };
                return(badminRole);
            }
        }
Ejemplo n.º 20
0
        public void SetAdminRoleStatus(int role_id, bool status)
        {
            if (this.CurrentUserPermission.UPDATE_ADMIN_ROLE == 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("分组信息不存在");
                }

                role.enabled = status;
                db.SaveChanges();
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="roles"></param>
        /// <param name="user_id"></param>
        public void UpdateUserRoles(int[] roles, int user_id)
        {
            if (this.CurrentUserPermission.UPDATE_USER_PERMISSION == 0)
            {
                throw new KMJXCException("没有权限执行此操作");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                if (user_id == this.Shop.User_ID)
                {
                    if (CurrentUser.ID != user_id)
                    {
                        throw new KMJXCException("您没有权限更新店铺掌柜的权限");
                    }
                }

                List <Admin_User_Role> uRoles = (from role in db.Admin_User_Role where role.user_id == user_id select role).ToList <Admin_User_Role>();
                int[] userRoles = (from role in uRoles select role.role_id).ToArray <int>();

                foreach (int role in roles)
                {
                    if (!userRoles.Contains(role))
                    {
                        Admin_User_Role uRole = new Admin_User_Role()
                        {
                            role_id = role, user_id = user_id
                        };
                        db.Admin_User_Role.Add(uRole);
                    }
                }

                foreach (Admin_User_Role role in uRoles)
                {
                    if (!roles.Contains(role.role_id))
                    {
                        db.Admin_User_Role.Remove(role);
                    }
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Add new mall in local db
        /// </summary>
        /// <param name="mall"></param>
        /// <returns></returns>
        public bool AddNewMall(Mall_Type mall)
        {
            bool result = false;

            if (mall == null)
            {
                return(result);
            }
            if (string.IsNullOrEmpty(mall.Name))
            {
                return(result);
            }
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                db.Mall_Type.Add(mall);
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bugId"></param>
        /// <param name="user_id"></param>
        /// <returns></returns>
        public bool ResolveBug(int bugId, int user_id)
        {
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug existed = (from b in db.Bug where b.ID == bugId select b).FirstOrDefault <Bug>();
                if (existed == null)
                {
                    throw new KMJXCException("所需更新的Bug信息不存在");
                }

                existed.Status      = 6;
                existed.Resolved    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                existed.Resolved_By = user_id;
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 24
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="action"></param>
        public void CreateActionLog(BUserActionLog action)
        {
            if (action == null)
            {
                return;
            }

            if (action.Shop == null)
            {
                return;
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                User_Action_Log log = new User_Action_Log();

                log.Action = action.Action.Action_ID;

                log.Description = action.Description;
                if (action.User != null && action.User.ID > 0)
                {
                    log.User_ID = action.User.ID;
                }
                else
                {
                    log.User_ID = this.CurrentUser.ID;
                }

                log.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                if (string.IsNullOrEmpty(log.Description))
                {
                    log.Description = "";
                }
                if (action.Shop != null)
                {
                    log.Shop_ID = action.Shop.ID;
                }
                db.User_Action_Log.Add(log);
                db.SaveChanges();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bug"></param>
        /// <returns></returns>
        public bool UpdateBug(BBug bug)
        {
            if (bug.Modified_By == null)
            {
                throw new KMJXCException("更新Bug时必须有更新人");
            }
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug existed = (from b in db.Bug where b.ID == bug.ID select b).FirstOrDefault <Bug>();
                if (existed == null)
                {
                    throw new KMJXCException("所需更新的Bug信息不存在");
                }

                if (bug.Status != null)
                {
                    existed.Status = bug.Status.ID;
                }

                if (bug.Modified_By != null)
                {
                    existed.Modified_By = bug.Modified_By.ID;
                    existed.Modified    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }
                if (!string.IsNullOrEmpty(bug.Title))
                {
                    existed.Title = bug.Title;
                }

                if (!string.IsNullOrEmpty(bug.Description))
                {
                    existed.Description = bug.Description;
                }
                db.SaveChanges();
                result = true;
            }
            return(result);
        }
Ejemplo n.º 26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="info"></param>
 public void SetCorpInfo(Corp_Info info)
 {
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         Corp_Info        first    = (from ci in db.Corp_Info orderby ci.ID ascending select ci).FirstOrDefault <Corp_Info>();
         List <Corp_Info> currents = (from ci in db.Corp_Info where ci.IsCurrent == true select ci).ToList <Corp_Info>();
         foreach (Corp_Info ci in currents)
         {
             ci.IsCurrent = false;
         }
         info.IsCurrent   = true;
         info.Modified    = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
         info.Modified_By = this.CurrentUser.ID;
         if (first != null)
         {
             info.Created    = first.Created;
             info.Created_By = first.Created_By;
         }
         db.Corp_Info.Add(info);
         db.SaveChanges();
     }
 }
Ejemplo n.º 27
0
        /// <summary>
        /// Update user object
        /// </summary>
        /// <param name="newUser"></param>
        public void UpdateUser(BUser user)
        {
            if (this.CurrentUserPermission.UPDATE_USER == 0)
            {
                throw new UserException("没有权限创建新用户");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var old = from ou in db.User where ou.User_ID == user.ID select ou;

                User dbUser = old.FirstOrDefault <User>();
                if (dbUser != null)
                {
                    dbUser.User_ID   = user.ID;
                    dbUser.Mall_ID   = user.Mall_ID;
                    dbUser.Mall_Name = user.Mall_Name;
                    dbUser.Name      = user.Name;
                    dbUser.Password  = user.Password;
                    //dbUser.Mall_Type = user.Type.Mall_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;
                    }

                    Employee employee = (from em in db.Employee where em.User_ID == dbUser.User_ID select em).FirstOrDefault <Employee>();
                    if (employee != null)
                    {
                        base.UpdateProperties(employee, user.EmployeeInfo);
                    }
                }
                db.SaveChanges();
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public void CreateNewResponse(int bugId, string response)
        {
            if (response == null)
            {
                throw new KMJXCException("问题创建失败");
            }

            if (bugId <= 0)
            {
                throw new KMJXCException("问题创建失败");
            }
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Bug_Response resp = new Bug_Response();

                resp.BugID       = bugId;
                resp.Create_By   = this.currentUser.ID;
                resp.Created     = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                resp.Description = response;

                db.Bug_Response.Add(resp);
                db.SaveChanges();
            }
        }
Ejemplo n.º 29
0
        public bool UpdatePassword(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("用户不存在");
                }

                user.Password = Encrypt.MD5(password);
                db.SaveChanges();
                result = true;
            }

            return(result);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Sync actions with Permission object
        /// </summary>
        public void SyncPermissionWithAction()
        {
            Type permission = typeof(Permission);

            FieldInfo[] fields = permission.GetFields();
            if (fields == null || fields.Length <= 0)
            {
                return;
            }

            KuanMaiEntities db = new KuanMaiEntities();

            try
            {
                foreach (FieldInfo field in fields)
                {
                    var action = from a in db.Admin_Action where a.action_name == field.Name select a;
                    if (action == null || action.ToList <Admin_Action>().Count == 0)
                    {
                        Admin_Action new_action = new Admin_Action();
                        new_action.action_name        = field.Name;
                        new_action.action_description = field.Name;
                        new_action.enable             = true;
                        db.Admin_Action.Add(new_action);
                    }
                }
                db.SaveChanges();
            }
            catch (DbEntityValidationException ex)
            {
            }
            finally
            {
                db.Dispose();
            }
        }