Exemple #1
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;
        }
Exemple #2
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;
        }
Exemple #3
0
 static BBaseManager()
 {
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         Areas = (from area in db.Common_District select area).ToList<Common_District>();
     }
 }
Exemple #4
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;
 }
Exemple #5
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="child_shop_id"></param>
        /// <returns></returns>
        public bool AddChildShop(int mall_type,string child_shop_name)
        {
            bool result = false;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Shop shop = (from sp in db.Shop where sp.Name == child_shop_name && sp.Mall_Type_ID==mall_type select sp).FirstOrDefault<Shop>();
                if (shop == null)
                {
                    throw new KMJXCException("您要添加的子店铺(" + child_shop_name + ")信息不存在,请先使用子店铺的主账户登录进销存,然后在执行添加子店铺操作");
                }

                if (shop.Parent_Shop_ID > 0)
                {
                    Shop mainshop = (from sp in db.Shop where sp.Shop_ID==shop.Parent_Shop_ID select sp).FirstOrDefault<Shop>();
                    if (mainshop != null)
                    {
                        throw new KMJXCException(child_shop_name+" 已经是 "+mainshop.Name+" 的子店铺,不能重复添加或者添加为别的店铺的子店铺");
                    }
                }

                result = this.AddChildShop(this.Shop, shop);
            }

            return result;
        }
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
            string user_id = filterContext.HttpContext.User.Identity.Name;
            if (string.IsNullOrEmpty(user_id)) {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=登录信息过期,请重新登录");
            }
            //Verify if the cookie user is a valid user
            UserManager userMgr = new UserManager(int.Parse(user_id),null);
            BUser user = userMgr.CurrentUser;

            if (user == null)
            {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=登录信息丢失,请重新登录并授权");
            }

            //Verify if logon user already has access token in db
            KuanMaiEntities db = new KuanMaiEntities();

            Access_Token token = (from t in db.Access_Token where t.User_ID == user.ID && t.Mall_Type_ID == user.Type.ID select t).FirstOrDefault<Access_Token>();

            if (token == null) {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=没有授权信息,请登录并授权");
            }

            //Verify if the existed access token is expired
            long timeNow = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
            if (timeNow >= token.Request_Time + token.Expirse_In)
            {
                filterContext.HttpContext.Response.Redirect("/Home/Login?message=授权信息已经过期,请重新登录并授权");
            }
        }
Exemple #7
0
 /// <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;
 }
Exemple #8
0
 /// <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;
 }
Exemple #9
0
        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;
        }
Exemple #10
0
        /// <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;
        }
Exemple #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;
 }
Exemple #12
0
 /// <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;
 }
Exemple #13
0
 /// <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;
 }
Exemple #14
0
        protected Mall_Type GetMallType()
        {
            Mall_Type type = null;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var t = from tp in db.Mall_Type where tp.Mall_Type_ID == this.Mall_Type_ID select tp;
                if (t.ToList<Mall_Type>().Count == 1)
                {
                    type = t.ToList<Mall_Type>()[0];
                }
            }

            return type;
        }
Exemple #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();
                }
            }
        }
Exemple #16
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();
                }
            }
        }
Exemple #17
0
        public Access_Token GetLocAccessToken(long user_id)
        {
            Access_Token token = null;

            KuanMaiEntities db = new KuanMaiEntities();

            var etoken = from p in db.Access_Token where p.Mall_Type_ID == this.Mall_Type_ID && p.User_ID == user_id select p;

            if (etoken != null)
            {
                token = etoken.ToList<Access_Token>()[0];
            }

            return token;
        }
Exemple #18
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buyPrice"></param>
        /// <returns></returns>
        public bool CreateBuyPrice(BBuyPrice buyPrice)
        {
            bool result = false;

            if (this.CurrentUserPermission.CREATE_BUY_PRICE == 0)
            {
                throw new KMJXCException("没有权限创建采购询价单");
            }

            if (buyPrice == null)
            {
                throw new KMJXCException("输入不正确");
            }

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                Buy_Price dbBuyPrice = new Buy_Price();
                if (buyPrice.Created <= 0)
                {
                    dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                }

                dbBuyPrice.Shop_ID = this.Shop.Shop_ID;
                if (buyPrice.Shop != null && buyPrice.Shop.ID > 0)
                {
                    dbBuyPrice.Shop_ID = buyPrice.Shop.ID;
                }

                dbBuyPrice.User_ID = this.CurrentUser.ID;
                if (buyPrice.User != null && buyPrice.User.ID > 0)
                {
                    dbBuyPrice.User_ID = buyPrice.User.ID;
                }

                dbBuyPrice.Created = DateTimeUtil.ConvertDateTimeToInt(DateTime.Now);
                dbBuyPrice.Title = buyPrice.Title;
                dbBuyPrice.Description = buyPrice.Desc;
                db.Buy_Price.Add(dbBuyPrice);
                db.SaveChanges();
                result = true;
                if (dbBuyPrice.ID > 0 && buyPrice.Details!=null && buyPrice.Details.Count>0)
                {
                    result = result & this.SaveBuyPriceDetails(buyPrice.Details, dbBuyPrice.ID);
                }
            }

            return result;
        }
Exemple #19
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;
        }
Exemple #20
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;
        }
Exemple #21
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;
 }
Exemple #22
0
 public BUser GetUserInfo(int user_id)
 {
     BUser user = null;
     using (KuanMaiEntities db = new KuanMaiEntities())
     {
         user = (from u in db.User
                 where u.User_ID == user_id
                 select new BUser
                     {
                         ID=u.User_ID,
                         Name=u.Name,
                         Mall_ID=u.Mall_ID,
                         Mall_Name=u.Mall_Name,
                         IsSystemUser=u.IsSystemUser,
                         NickName=u.NickName
                     }).FirstOrDefault<BUser>();
     }
     return user;
 }
Exemple #23
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();
     }
 }
Exemple #24
0
        public static SystemAdmin Login(string name, string password)
        {
            SystemAdmin adminInstance = null;
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                User user = (from u in db.User where u.IsSystemUser == true && u.Name == name select u).FirstOrDefault<User>();
                if (user == null)
                {
                    throw new KMJXCException("用户名不存在");
                }

                string md5Password = Encrypt.MD5(password);

                if (md5Password != user.Password)
                {
                    throw new KMJXCException("密码不正确");
                }

                adminInstance = new SystemAdmin(user.User_ID);
            }

            return adminInstance;
        }
Exemple #25
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();
            }
        }
Exemple #26
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool UpdateEmployeeInfo(Employee employee)
        {
            bool result = false;
            if (this.CurrentUserPermission.UPDATE_EMPLOYEE == 0)
            {
                throw new KMJXCException("没有权限更新员工信息");
            }
            KuanMaiEntities db = new KuanMaiEntities();
            try
            {
                User user = (from u in db.User where u.User_ID == employee.User_ID select u).FirstOrDefault<User>();
                if (user != null)
                {
                    Employee existing = (from e in db.Employee where e.User_ID == employee.User_ID select e).FirstOrDefault<Employee>();
                    if (existing == null)
                    {
                        db.Employee.Add(employee);
                    }
                    else
                    {
                        this.UpdateProperties(existing, employee);
                    }
                    result = true;
                }
            }
            catch
            {

            }
            finally
            {
                if (db != null)
                {
                    db.Dispose();
                }
            }

            return result;
        }
Exemple #27
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="shop_id"></param>
        /// <returns></returns>
        public bool SyncShopSubUsers(int shop_id)
        {
            bool result = false;

            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                BUser dbUser = (from us in db.User
                                from sp in db.Shop
                                where us.User_ID == sp.User_ID && sp.Shop_ID == shop_id
                                select new BUser
                                {
                                    ID = us.User_ID,
                                    //EmployeeInfo = (from e in db.Employee where e.User_ID == us.User_ID select e).FirstOrDefault<Employee>(),
                                    Mall_ID = us.Mall_ID,
                                    Mall_Name = us.Mall_Name,
                                    Type = (from type in db.Mall_Type where type.Mall_Type_ID == us.Mall_Type
                                            select new BMallType { ID=type.Mall_Type_ID,Name=type.Name,Description=type.Description }).FirstOrDefault<BMallType>(),
                                    Parent_ID = (int)us.Parent_User_ID,
                                    Parent = null,
                                    Name = us.Name,
                                    Password = us.Password
                                }).FirstOrDefault<BUser>();

                if (dbUser == null)
                {
                    throw new KMJXCException("没有找到对应店铺的卖家信息");
                }

                List<BUser> subUsers = this.MallUserManager.GetSubUsers(dbUser);
                List<BUser> existedUsers = (from us in db.User
                                            from sp in db.Shop_User
                                            where us.User_ID == sp.User_ID && sp.Shop_ID == shop_id
                                            select new BUser
                                            {
                                                ID = us.User_ID,
                                                //EmployeeInfo = (from e in db.Employee where e.User_ID == us.User_ID select e).FirstOrDefault<Employee>(),
                                                Mall_ID = us.Mall_ID,
                                                Mall_Name = us.Mall_Name,
                                                Type = (from type in db.Mall_Type where type.Mall_Type_ID == us.Mall_Type
                                                        select new BMallType { ID=type.Mall_Type_ID,Name=type.Name,Description=type.Description }).FirstOrDefault<BMallType>(),
                                                Parent_ID = (int)us.Parent_User_ID,
                                                Parent = null,
                                                Name = us.Name,
                                                Password = us.Password
                                            }).ToList<BUser>();

                foreach (BUser user in subUsers)
                {
                    bool found = false;
                    foreach (BUser eUser in existedUsers)
                    {
                        if (user.Mall_ID == eUser.Mall_ID && user.Mall_Name == eUser.Mall_Name)
                        {
                            //Update user
                            found = true;
                            eUser.EmployeeInfo = user.EmployeeInfo;
                            eUser.Name = user.Name;
                            break;
                        }
                    }

                    if (!found)
                    {
                        //add new sub user
                        User dbUser1 = new User();
                        //dbUser1.User_ID = user.ID;
                        dbUser1.Mall_ID = user.Mall_ID;
                        dbUser1.Mall_Name = user.Mall_Name;
                        dbUser1.Name = user.Name;
                        dbUser1.Mall_Type = user.Type.ID;
                        if (user.Parent != null)
                        {
                            dbUser1.Parent_Mall_ID = user.Parent.Mall_ID;
                            dbUser1.Parent_Mall_Name = user.Parent.Mall_Name;
                            dbUser1.Parent_User_ID = user.Parent.ID;
                        }
                        db.User.Add(dbUser1);
                        db.SaveChanges();

                        if (user.EmployeeInfo != null && dbUser1.User_ID>0)
                        {
                            Employee employee = new Employee();
                            employee.Name = user.EmployeeInfo.Name;
                            employee.IdentityCard = user.EmployeeInfo.IdentityCard;
                            employee.MatureDate = user.EmployeeInfo.MatureDate;
                            employee.Phone = user.EmployeeInfo.Phone;
                            employee.User_ID = user.EmployeeInfo.User_ID;
                            employee.HireDate = user.EmployeeInfo.HireDate;
                            employee.Gendar = user.EmployeeInfo.Gendar;
                            employee.Duty = user.EmployeeInfo.Duty;
                            employee.Email = user.EmployeeInfo.Email;
                            employee.Department = user.EmployeeInfo.Department;
                            employee.BirthDate = user.EmployeeInfo.BirthDate;
                            employee.Address = user.EmployeeInfo.Address;
                            db.Employee.Add(employee);
                        }

                        Shop_User sp = new Shop_User();
                        sp.Shop_ID = shop_id;
                        sp.User_ID = dbUser1.User_ID;
                        db.Shop_User.Add(sp);
                    }
                }

                db.SaveChanges();
            }

            return result;
        }
Exemple #28
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public List<BUser> GetUsers(int page,int pageSize,out int total,int shop_id=0,bool paging=false)
        {
            List<BUser> users = new List<BUser>();
            total = 0;
            int shop = this.Shop.Shop_ID;
            if (shop_id > 0)
            {
                shop = shop_id;
            }
            using (KuanMaiEntities db = new KuanMaiEntities())
            {
                var usersobj = from user in db.User
                               join type in db.Mall_Type on user.Mall_Type equals type.Mall_Type_ID into Ltype
                               from l_type in Ltype.DefaultIfEmpty()
                               where user.Shop_ID == shop
                               select new BUser
                               {
                                   ID = user.User_ID,
                                   Name = user.Name,
                                   Mall_Name = user.Mall_Name,
                                   Mall_ID = user.Mall_ID,

                                   Parent_ID = (int)user.Parent_User_ID,
                                   Password = user.Password,
                                   Type = new BMallType
                                   {
                                       Name = l_type.Name,
                                       ID = l_type.Mall_Type_ID,
                                       Description = l_type.Description
                                   }
                               };

                total = usersobj.Count();
                if (paging)
                {
                    usersobj = usersobj.OrderBy(a => a.ID).Skip((page - 1) * pageSize).Take(pageSize);
                }
                users = usersobj.ToList<BUser>();
            }

            return users;
        }
Exemple #29
0
 /// <summary>
 /// Get user by id
 /// </summary>
 /// <param name="user_Id"></param>
 /// <returns></returns>       
 public BUser GetUser(int user_Id)
 {
     BUser user = null;
     KuanMaiEntities db = new KuanMaiEntities();
     try
     {
         var us = from u in db.User
                  where u.User_ID == user_Id
                  select new BUser
                      {
                          ID = u.User_ID,
                          EmployeeInfo = (from e in db.Employee
                                          where e.User_ID == u.User_ID
                                          select
                                              new BEmployee
                                              {
                                                 ID=e.Employee_ID,
                                                 Name=e.Name
                                              }).FirstOrDefault<BEmployee>(),
                          Mall_ID = u.Mall_ID,
                          Mall_Name = u.Mall_Name,
                          Name = u.Name,
                          Password = u.Password,
                          Parent_ID = (int)u.Parent_User_ID,
                          Type = (from t in db.Mall_Type where t.Mall_Type_ID == u.Mall_Type
                                  select new BMallType
                                  {
                                      ID=t.Mall_Type_ID,
                                      Name=t.Name
                                  }).FirstOrDefault<BMallType>(),
                      };
         user = us.FirstOrDefault<BUser>();
         if (user.Parent_ID > 0)
         {
             user.Parent = this.GetUser(user.Parent_ID);
         }
     }
     catch
     {
     }
     return user;
 }
Exemple #30
0
 /// <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;
 }