Esempio n. 1
0
        public ActionResult ReDisableStores(string SID)
        {
            string[]   strIds = SID.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            List <int> list   = new List <int>();

            foreach (string id in strIds)
            {
                list.Add(int.Parse(id));
            }

            var            flag          = false;
            IStoresService storesService = ServiceFactory.Create <IStoresService>();

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var item in list)
                {
                    var data = storesService.GetEntity(item);
                    data.Disabled = false;
                    storesService.UpdateEntity(data);
                }
                scope.Complete();
                flag = true;
            }

            return(Json(new Result(flag, ResultType.Other), JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public JsonResult DeleteUsers(string IDs)
        {
            List <int>    idArr        = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            IUsersService usersService = ServiceFactory.Create <IUsersService>();
            var           data         = usersService.GetEntities(idArr);

            bool flage = true;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var item in data)
                {
                    item.Disabled = true;
                    flage         = usersService.UpdateEntity(item);
                    if (flage == false)
                    {
                        break;
                    }
                }
                scope.Complete();
            }


            return(Json(new Result(flage, ResultType.Other), JsonRequestBehavior.AllowGet));
        }
        /// <summary>
        /// 设置用户角色
        /// </summary>
        /// <param name="UserIDs"></param>
        /// <param name="RoleIDs"></param>
        /// <returns></returns>
        public JsonResult SetUserRole(string UserIDs, string RoleIDs)
        {
            if (string.IsNullOrWhiteSpace(UserIDs) || string.IsNullOrWhiteSpace(RoleIDs))
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            List <int> userIDArr = UserIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> roleIDArr = RoleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            if (!CurrentInfo.IsAdministrator && userIDArr.Contains(1330))
            {
                return(Json(new Result(false, "拒绝修改"), JsonRequestBehavior.AllowGet));
            }

            IRelationUserRoleService relationUserRoleService = ServiceFactory.Create <IRelationUserRoleService>();
            List <RelationUserRole>  listRelationUserRole    = new List <RelationUserRole>();
            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var userID in userIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var userRoles = relationUserRoleService.GetEntities(t => t.UserID == userID);
                    relationUserRoleService.DeleteEntities(userRoles.ToList());
                    foreach (var roleID in roleIDArr)
                    {
                        RelationUserRole model = new RelationUserRole();
                        model.UserID       = userID;
                        model.RoleID       = roleID;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        listRelationUserRole.Add(model);
                    }
                }
                addCount = relationUserRoleService.AddEntities(listRelationUserRole).Count();
                scope.Complete();
            }

            return(Json(new Result(addCount > 0, "成功分配用户角色"), JsonRequestBehavior.AllowGet));
        }
Esempio n. 4
0
        public ActionResult EditShops(ShopModel shopModel)
        {
            IUsersService  usersService  = ServiceFactory.Create <IUsersService>();
            IShopsService  shopsService  = ServiceFactory.Create <IShopsService>();
            IStoresService storesService = ServiceFactory.Create <IStoresService>();

            if (string.IsNullOrWhiteSpace(shopModel.ProvinceCode) || string.IsNullOrWhiteSpace(shopModel.CityCode) || string.IsNullOrWhiteSpace(shopModel.CountyCode))
            {
                return(Json(new Result(false, "省、市、县必填"), JsonRequestBehavior.AllowGet));
            }

            bool flage = shopsService.Exists(t => t.ID != shopModel.ID && t.ShopName == shopModel.ShopName);

            if (flage)
            {
                return(Json(new Result(false, "已经存在同名商家,请修改"), JsonRequestBehavior.AllowGet));
            }
            //判断是改变了版本
            bool versionHasChange = false;
            bool saveSuccess      = false;

            //用事务来更新一个商家
            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                //商家信息
                Shops shops = shopsService.GetEntity(shopModel.ID);
                shops.ShopName   = shopModel.ShopName;
                shops.Domain     = shopModel.Domain;
                shops.DomainName = shopModel.DomainName;
                //如果版本改变了,则需要重置商家的菜单
                if (shops.ShopVersionID != shopModel.ShopVersionID)
                {
                    versionHasChange = true;
                }
                shops.ShopVersionID = shopModel.ShopVersionID;
                shops.DueDate       = shopModel.DueDate;
                shops.TotalMoney    = shopModel.TotalMoney;
                shops.Remark        = shopModel.Remark;
                shops.Disabled      = shopModel.Disabled;

                shops.ShopType      = shopModel.ShopType;
                shops.SalespersonID = shopModel.SalespersonID;
                shops.Deposit       = shopModel.Deposit;
                shops.FinalPayment  = shopModel.FinalPayment;
                shops.Province      = shopModel.Province;
                shops.ProvinceCode  = shopModel.ProvinceCode;
                shops.City          = shopModel.City;
                shops.CityCode      = shopModel.CityCode;
                shops.County        = shopModel.County;
                shops.CountyCode    = shopModel.CountyCode;
                shops.AfterSales    = shopModel.AfterSales;
                shops.LogoUrl       = shopModel.LogoUrl;
                shops.AnnualFee     = shopModel.AnnualFee;
                shops.SiteName      = shopModel.SiteName;

                bool update1 = shopsService.UpdateEntity(shops);

                //商家账号
                Users users = usersService.GetEntity(shops.AdminUserID);
                users.RealName = shopModel.RealName;
                users.UserName = shopModel.UserName;
                //如果用户修改了密码,则要重新生成密码规则
                if (users.Password != shopModel.Password)
                {
                    //修改账号PasswordSalt要判断是否是管理员
                    users.PasswordSalt = Common.TextFilter.GetPasswordSalt(UserIsAdministrator(users));// Common.TextFilter.Substring(Guid.NewGuid().ToString("N"), 10, false);
                    string endPassword = shopModel.Password + users.PasswordSalt;
                    users.Password = Common.SecureHelper.MD5(endPassword);
                }

                users.Idcard   = shopModel.Idcard;
                users.Phone    = shopModel.Phone;
                users.Disabled = shopModel.Disabled;

                bool update2 = usersService.UpdateEntity(users);

                //如果版本修改了
                if (versionHasChange)
                {
                    ResetShopVersion(shopModel.ID, shopModel.ShopVersionID);
                }

                scope.Complete();
                saveSuccess = update1 && update2;
            }

            return(Json(new Result(saveSuccess, ResultType.Add), JsonRequestBehavior.AllowGet));

            //IShopsService shopsService = ServiceFactory.Create<IShopsService>();
            //bool flag = shopsService.Exists(t => t.ID != shopModel.ID && string.Equals(t.ShopName, shopModel.ShopName, StringComparison.OrdinalIgnoreCase));
            //if (flag)
            //{
            //    return Json(new Result(false, "该商家已存在"), JsonRequestBehavior.AllowGet);
            //}
            //bool IsSuccess = shopsService.UpdateEntity(shopModel);
            //return Json(new Result(IsSuccess, ResultType.Update), JsonRequestBehavior.AllowGet);
        }
Esempio n. 5
0
        //public int nowAddShopID = 0;


        public Shops CreateShop(ShopModel shopModel, int createUserID = 0)
        {
            IUsersService  usersService  = ServiceFactory.Create <IUsersService>();
            IShopsService  shopsService  = ServiceFactory.Create <IShopsService>();
            IStoresService storesService = ServiceFactory.Create <IStoresService>();

            if (createUserID == 0)
            {
                createUserID = CurrentInfo.CurrentUser.ID;
            }

            //bool saveSuccess = false;
            Shops shops = null;

            //用事务来添加一个商家
            using (TransactionScope scope = TransactionScopeHelper.GetTran(TransactionScopeOption.Required, TimeSpan.FromSeconds(20)))
            {
                //商家账号
                Users users = new Users();
                users.RealName = shopModel.RealName;
                users.UserName = shopModel.UserName;
                //添加账号PasswordSalt随机
                users.PasswordSalt = Common.TextFilter.GetPasswordSalt(); //Common.TextFilter.Substring(Guid.NewGuid().ToString("N"), 10, false);
                string endPassword = shopModel.Password + users.PasswordSalt;
                users.Password    = Common.SecureHelper.MD5(endPassword);
                users.NeedAccount = true;

                users.Idcard         = shopModel.Idcard;
                users.Phone          = shopModel.Phone;
                users.DefaultStoreID = null;
                users.CreateUserID   = createUserID;
                users.CreateTime     = DateTime.Now;
                users.Disabled       = shopModel.Disabled;

                users = usersService.AddEntity(users);

                //商家信息
                shops               = new Shops();
                shops.ShopName      = shopModel.ShopName;
                shops.Domain        = shopModel.Domain;
                shops.DomainName    = shopModel.DomainName;
                shops.DueDate       = shopModel.DueDate;
                shops.TotalMoney    = shopModel.TotalMoney;
                shops.Remark        = shopModel.Remark;
                shops.AdminUserID   = users.ID;
                shops.CreateUserID  = createUserID;
                shops.CreateTime    = DateTime.Now;
                shops.Disabled      = shopModel.Disabled;
                shops.ShopVersionID = shopModel.ShopVersionID;
                shops.ShopType      = shopModel.ShopType;
                shops.SalespersonID = shopModel.SalespersonID;
                shops.Deposit       = shopModel.Deposit;
                shops.FinalPayment  = shopModel.FinalPayment;
                shops.Province      = shopModel.Province;
                shops.ProvinceCode  = shopModel.ProvinceCode;
                shops.City          = shopModel.City;
                shops.CityCode      = shopModel.CityCode;
                shops.County        = shopModel.County;
                shops.CountyCode    = shopModel.CountyCode;
                shops.AfterSales    = shopModel.AfterSales;
                shops.LogoUrl       = shopModel.LogoUrl;
                shops.AnnualFee     = shopModel.AnnualFee;
                shops.SiteName      = shopModel.SiteName;

                //默认赋值
                {
                    shops.DueDate       = DateTime.MaxValue;
                    shops.TotalMoney    = 0;
                    shops.Disabled      = false;
                    shops.ShopVersionID = 1;
                }

                shops = shopsService.AddEntity(shops);

                //门店(开通商家的时候默认开通一号店)
                Stores stores = new Stores();
                stores.ShopId       = shops.ID;
                stores.StoreName    = "一号部门";
                stores.IsShare      = false;
                stores.IsShowWeiXin = false;
                stores.IsMainStore  = false;

                stores = storesService.AddEntity(stores);

                users.ShopsID        = shops.ID;
                users.DefaultStoreID = stores.ID;
                usersService.UpdateEntity(users);

                //Category categoryModel = new Category();
                //categoryModel.Name = "总仓";
                //categoryModel.Sort = 1;
                //categoryModel.CategoryType = 3;
                //categoryModel.Name = categoryModel.Name.Trim();
                //categoryModel.UserID = users.ID;
                //categoryModel.CreateTime = DateTime.Now;
                //categoryModel.StoreID = stores.ID;
                //categoryModel = categoryModel.Add();

                //Role roleModel = new Role();
                //roleModel.Name = "经理";
                //roleModel.Sort = 1;
                //roleModel.ShopsID = shops.ID;
                //roleModel.StoreID = stores.ID;
                //roleModel.CreateUserID = users.ID;
                //roleModel.CreateTime = DateTime.Now;
                //roleModel = roleModel.Add();


                //这边要取出这个版本所有菜单,然后加到用户菜单关系表 和 商家菜单关系表中
                IRelationShopVersionModuleService relationShopVersionModuleService = ServiceFactory.Create <IRelationShopVersionModuleService>();
                var listModuleID = relationShopVersionModuleService.GetEntities(t => t.ShopVersionID == shopModel.ShopVersionID).Select(t => t.ModuleID).ToList();
                var strModuleID  = string.Join(",", listModuleID.ToArray());

                //添加商家和菜单的关系
                AddRelationShopModule(shops.ID.ToString(), strModuleID, createUserID);
                //添加门店和菜单的关系
                AddRelationStoreModule(stores.ID.ToString(), strModuleID, createUserID);
                //添加用户和菜单的关系
                AddRelationUsersModule(users.ID.ToString(), strModuleID, createUserID);
                ////添加角色和菜单的关系
                //AddRelationRoleModule(roleModel.ID.ToString(), strModuleID, createUserID);
                scope.Complete();
            }

            return(shops);
        }
Esempio n. 6
0
        private bool AddRelationUsersModule(string IDs, string ModuleIDs, int createUserID = 0)
        {
            if (string.IsNullOrWhiteSpace(IDs) || string.IsNullOrWhiteSpace(ModuleIDs))
            {
                return(false);
            }
            if (createUserID == 0)
            {
                createUserID = CurrentInfo.CurrentUser.ID;
            }


            List <int> userIDArr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> moduleArr = ModuleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            //把所有菜单的父菜单取出来,但是只能保证三级菜单,多级有可能有bug
            IModuleService moduleService = ServiceFactory.Create <IModuleService>();
            List <Module>  allListModule = new List <Module>();

            allListModule.AddRange(moduleService.GetEntities(t => moduleArr.Contains(t.ID)).ToList());
            //foreach (var item in allListModule)
            //{
            //    Module parentModule = moduleService.GetFirstOrDefault(t => t.ID == item.ParentID);
            //    if (parentModule != null)
            //    {
            //        if (allListModule.Where(t => t.ID == parentModule.ID).Count() == 0)
            //        {
            //            allListModule.Add(parentModule);
            //        }
            //    }
            //}

            for (int i = 0; i < allListModule.Count(); i++)
            {
                int    parentID     = allListModule[i].ParentID;
                Module parentModule = moduleService.GetFirstOrDefault(t => t.ID == parentID);
                if (parentModule != null)
                {
                    if (allListModule.Where(t => t.ID == parentModule.ID).Count() == 0)
                    {
                        allListModule.Add(parentModule);
                    }
                }
            }
            //从新生成菜单ID
            moduleArr = allListModule.Select(t => t.ID).ToList();

            IRelationUsersModuleService relationUsersModuleService = ServiceFactory.Create <IRelationUsersModuleService>();

            List <RelationUsersModule> listRelationUsersModule = new List <RelationUsersModule>();
            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var userID in userIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var userModule = relationUsersModuleService.GetEntities(t => t.UsersID == userID);
                    relationUsersModuleService.DeleteEntities(userModule.ToList());
                    foreach (var moduleID in moduleArr)
                    {
                        RelationUsersModule model = new RelationUsersModule();
                        model.UsersID      = userID;
                        model.ModuleID     = moduleID;
                        model.CreateUserID = createUserID;
                        model.CreateTime   = DateTime.Now;
                        listRelationUsersModule.Add(model);
                    }
                }
                addCount = relationUsersModuleService.AddEntities(listRelationUsersModule).Count();
                scope.Complete();
            }
            if (addCount > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public JsonResult AddRelationStoreModule(string IDs, string ModuleIDs)
        {
            if (string.IsNullOrWhiteSpace(IDs) || string.IsNullOrWhiteSpace(ModuleIDs))
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            List <int> storesIDArr = IDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();
            List <int> moduleArr   = ModuleIDs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            //把所有菜单的父菜单取出来,但是只能保证三级菜单,多级有可能有bug
            IModuleService moduleService = ServiceFactory.Create <IModuleService>();
            List <Module>  allListModule = new List <Module>();

            allListModule.AddRange(moduleService.GetEntities(t => moduleArr.Contains(t.ID)).ToList());

            //复制一份副本,用于循环使用
            Module[] tempAllListModule = new Module[allListModule.Count];
            allListModule.CopyTo(tempAllListModule);

            foreach (var item in tempAllListModule)
            {
                Module parentModule = moduleService.GetFirstOrDefault(t => t.ID == item.ParentID);
                if (parentModule != null)
                {
                    if (allListModule.Where(t => t.ID == parentModule.ID).Count() == 0)
                    {
                        allListModule.Add(parentModule);
                    }
                }
            }
            //从新生成菜单ID
            moduleArr = allListModule.Select(t => t.ID).ToList();

            IRelationStoresModuleService relationStoresModuleService = ServiceFactory.Create <IRelationStoresModuleService>();

            List <RelationStoresModule> listRelationStoresModule = new List <RelationStoresModule>();
            int addCount = 0;

            using (TransactionScope scope = TransactionScopeHelper.GetTran())
            {
                foreach (var storeID in storesIDArr)
                {
                    //删除当前人员的所有的权限,然后在添加新的权限
                    var userModule = relationStoresModuleService.GetEntities(t => t.StoresID == storeID);
                    relationStoresModuleService.DeleteEntities(userModule.ToList());
                    foreach (var moduleID in moduleArr)
                    {
                        RelationStoresModule model = new RelationStoresModule();
                        model.StoresID     = storeID;
                        model.ModuleID     = moduleID;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        listRelationStoresModule.Add(model);
                    }
                }
                addCount = relationStoresModuleService.AddEntities(listRelationStoresModule).Count();
                scope.Complete();
            }

            return(Json(new Result(addCount > 0, "成功分配权限"), JsonRequestBehavior.AllowGet));
        }
Esempio n. 8
0
        public JsonResult AddPrivilegesByType(string PType, int ID, string privilegesIDSs)
        {
            List <int> ids = privilegesIDSs.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(t => Convert.ToInt32(t)).ToList();

            if (PType.ToLower() == "SystemShow".ToLower())
            {
                using (TransactionScope sc = TransactionScopeHelper.GetTran())
                {
                    //删除系统的权限,重新添加
                    ServiceHelper.GetRelationPrivilegesSystemService.DeleteEntitiesByWhere(t => t.SystemID == ID);
                    foreach (var item in ids)
                    {
                        RelationPrivilegesSystem model = new RelationPrivilegesSystem();
                        model.SystemID     = ID;
                        model.PrivilegesID = item;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        model.Add();
                    }
                    sc.Complete();
                }

                return(Json(new Result(true, ResultType.Add), JsonRequestBehavior.AllowGet));
            }
            else if (PType.ToLower() == "ShopShow".ToLower())
            {
                using (TransactionScope sc = TransactionScopeHelper.GetTran())
                {
                    //删除商家的权限,重新添加
                    ServiceHelper.GetRelationPrivilegesShopsService.DeleteEntitiesByWhere(t => t.ShopsID == ID);
                    foreach (var item in ids)
                    {
                        RelationPrivilegesShops model = new RelationPrivilegesShops();
                        model.ShopsID      = ID;
                        model.PrivilegesID = item;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        model.Add();
                    }
                    sc.Complete();
                }

                return(Json(new Result(true, ResultType.Add), JsonRequestBehavior.AllowGet));
            }
            else if (PType.ToLower() == "StoreShow".ToLower())
            {
                using (TransactionScope sc = TransactionScopeHelper.GetTran())
                {
                    //删除门店的权限,重新添加
                    ServiceHelper.GetRelationPrivilegesStoresService.DeleteEntitiesByWhere(t => t.StoresID == ID);
                    foreach (var item in ids)
                    {
                        RelationPrivilegesStores model = new RelationPrivilegesStores();
                        model.StoresID     = ID;
                        model.PrivilegesID = item;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        model.Add();
                    }
                    sc.Complete();
                }

                return(Json(new Result(true, ResultType.Add), JsonRequestBehavior.AllowGet));
            }
            else if (PType.ToLower() == "RoleShow".ToLower())
            {
                using (TransactionScope sc = TransactionScopeHelper.GetTran())
                {
                    //删除门店的权限,重新添加
                    ServiceHelper.GetRelationPrivilegesRoleService.DeleteEntitiesByWhere(t => t.RoleID == ID);
                    foreach (var item in ids)
                    {
                        RelationPrivilegesRole model = new RelationPrivilegesRole();
                        model.RoleID       = ID;
                        model.PrivilegesID = item;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        model.Add();
                    }
                    sc.Complete();
                }

                return(Json(new Result(true, ResultType.Add), JsonRequestBehavior.AllowGet));
            }
            else if (PType.ToLower() == "UserShow".ToLower())
            {
                using (TransactionScope sc = TransactionScopeHelper.GetTran())
                {
                    //删除用户的权限,重新添加
                    ServiceHelper.GetRelationPrivilegesUsersService.DeleteEntitiesByWhere(t => t.UsersID == ID);
                    foreach (var item in ids)
                    {
                        RelationPrivilegesUsers model = new RelationPrivilegesUsers();
                        model.UsersID      = ID;
                        model.PrivilegesID = item;
                        model.CreateUserID = CurrentInfo.CurrentUser.ID;
                        model.CreateTime   = DateTime.Now;
                        model.Add();
                    }
                    sc.Complete();
                }

                return(Json(new Result(true, ResultType.Add), JsonRequestBehavior.AllowGet));
            }

            return(Json(new Result(false, ResultType.Other), JsonRequestBehavior.AllowGet));
        }
Esempio n. 9
0
        public JsonResult UpdateUser(Entity.Users user)
        {
            if (user.ID == 0)
            {
                return(Json(new Result(false, "参数错误"), JsonRequestBehavior.AllowGet));
            }

            IService.IUsersService usersService = ServiceFactory.Create <IUsersService>();
            var dbData = usersService.GetEntity(user.ID, false);

            //如果不是管理员,是不允许禁用店铺管理员账号的,包括店铺管理员自己也不行
            if (!CurrentInfo.IsAdministrator)
            {
                if (user.NeedAccount == false && user.ID == CurrentInfo.CurrentShop.AdminUserID)
                {
                    return(Json(new Result(false, "店铺管理员必须有登录账号"), JsonRequestBehavior.AllowGet));
                }
            }


            //是否需要账号
            if (user.NeedAccount)
            {
                if (string.IsNullOrWhiteSpace(user.UserName) || string.IsNullOrWhiteSpace(user.Password))
                {
                    return(Json(new Result(false, "用户名和密码不能为空,若无需账号请选择‘不需要登录账号’"), JsonRequestBehavior.AllowGet));
                }

                bool flage = usersService.Exists(t => t.ID != user.ID && t.UserName == user.UserName);
                if (flage)
                {
                    return(Json(new Result(false, "已经存在同名用户,请更换"), JsonRequestBehavior.AllowGet));
                }

                //判断用户是否修改了密码
                if (dbData.Password != user.Password)
                {
                    string endPassword = user.Password + dbData.PasswordSalt;
                    user.Password = Common.SecureHelper.MD5(endPassword);
                }
            }
            else
            {
                user.UserName     = null;
                user.Password     = null;
                user.PasswordSalt = null;
            }

            //user.DefaultStoreID = dbData.DefaultStoreID;
            user.ShopsID = dbData.ShopsID;

            if (!string.IsNullOrWhiteSpace(user.Photo))
            {
                if (dbData.Photo != user.Photo)
                {
                    //生成缩略图  并删除原图
                    string fileFullName = FileHelper.Move(user.Photo, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/");
                    string extension    = System.IO.Path.GetExtension(fileFullName);
                    //缩略图路径
                    string thumbnailPath = ImgHelper.GetThumbnailPathByWidth(fileFullName, 60);
                    //生成缩略图
                    ImgHelper.MakeThumbnail(
                        System.Web.HttpContext.Current.Server.MapPath(fileFullName),
                        System.Web.HttpContext.Current.Server.MapPath(thumbnailPath),
                        60,
                        60,
                        "W",
                        extension
                        );
                    FileHelper.DeleteFile(System.Web.HttpContext.Current.Server.MapPath(fileFullName));

                    user.Photo = thumbnailPath;
                }
            }
            else
            {
                user.Photo = dbData.Photo;
            }


            if (!string.IsNullOrWhiteSpace(user.IdcardPhoto))
            {
                if (dbData.IdcardPhoto != user.IdcardPhoto)
                {
                    user.IdcardPhoto = FileHelper.Move(user.IdcardPhoto, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/");
                }
            }
            else
            {
                user.IdcardPhoto = dbData.IdcardPhoto;
            }

            user.CreateUserID = dbData.CreateUserID;
            user.CreateTime   = dbData.CreateTime;
            user.Disabled     = dbData.Disabled;
            user.PasswordSalt = dbData.PasswordSalt;
            //保持上次登录的信息
            user.LastLoginArea = dbData.LastLoginArea;
            user.LastLoginIP   = dbData.LastLoginIP;
            user.LastLoginTime = dbData.LastLoginTime;
            user.LoginTimes    = dbData.LoginTimes;

            bool success = false;

            using (TransactionScope transactionScope = TransactionScopeHelper.GetTran())
            {
                success = usersService.UpdateEntity(user);
                //if (user.WorkTypeID != null)
                //{
                //    AdddRelationUserWorkType(user.ID, Convert.ToInt32(user.WorkTypeID));
                //}
                transactionScope.Complete();
            }

            //如果更新的是当前用户资料,则更新用户头像
            if (success && CurrentInfo.CurrentUser.ID == user.ID)
            {
                CurrentInfo.CurrentUser.Photo = user.Photo;
            }


            return(Json(new Result(success, ResultType.Update), JsonRequestBehavior.AllowGet));
        }
Esempio n. 10
0
        public JsonResult AddUser(Entity.Users user, int?shopType)
        {
            //如果是测试账号则默认门店设置在45下面
            if (user.IsIntention == true)
            {
                if (shopType == 1)
                {
                    user.DefaultStoreID = 45;
                }
                else if (shopType == 2)
                {
                    user.DefaultStoreID = 101;
                }
                else
                {
                    return(Json(new Result(false, "该版本还未开通,无法添加"), JsonRequestBehavior.AllowGet));
                }
            }

            IService.IUsersService usersService = ServiceFactory.Create <IUsersService>();
            //是否需要账号
            if (user.NeedAccount)
            {
                if (string.IsNullOrWhiteSpace(user.UserName) || string.IsNullOrWhiteSpace(user.Password))
                {
                    return(Json(new Result(false, "用户名和密码不能为空,若无需账号请选择‘不需要登录账号’"), JsonRequestBehavior.AllowGet));
                }

                bool flage = usersService.Exists(t => t.UserName == user.UserName);
                if (flage)
                {
                    return(Json(new Result(false, "已经存在同名用户,请更换"), JsonRequestBehavior.AllowGet));
                }
                //添加账号PasswordSalt随机
                user.PasswordSalt = Common.TextFilter.GetPasswordSalt();//Common.TextFilter.Substring(Guid.NewGuid().ToString("N"), 10, false);
                string endPassword = user.Password + user.PasswordSalt;
                //计算密码
                user.Password = Common.SecureHelper.MD5(endPassword);
            }

            //user.DefaultStoreID = CurrentInfo.CurrentStore.ID;
            IStoresService storesService = ServiceFactory.Create <IStoresService>();
            var            storesModel   = storesService.GetEntity(user.DefaultStoreID.ToString().ToInt32());

            user.ShopsID = storesModel.ShopId;

            if (!string.IsNullOrWhiteSpace(user.Photo))
            {
                //生成缩略图  并删除原图
                string fileFullName = FileHelper.Move(user.Photo, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/");
                string extension    = System.IO.Path.GetExtension(fileFullName);
                //缩略图路径
                string thumbnailPath = ImgHelper.GetThumbnailPathByWidth(fileFullName, 60);
                //生成缩略图
                ImgHelper.MakeThumbnail(
                    System.Web.HttpContext.Current.Server.MapPath(fileFullName),
                    System.Web.HttpContext.Current.Server.MapPath(thumbnailPath),
                    60,
                    60,
                    "W",
                    extension
                    );
                FileHelper.DeleteFile(System.Web.HttpContext.Current.Server.MapPath(fileFullName));

                user.Photo = thumbnailPath;

                //user.Photo = FileHelper.Move(user.Photo, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/");
            }

            if (!string.IsNullOrWhiteSpace(user.IdcardPhoto))
            {
                user.IdcardPhoto = FileHelper.Move(user.IdcardPhoto, "/Upload/Reality/" + CurrentInfo.CurrentStore.ID + "/UserImg/");
            }

            user.CreateUserID = CurrentInfo.CurrentUser.ID;
            user.CreateTime   = DateTime.Now;
            user.Disabled     = false;

            bool success = false;

            using (TransactionScope transactionScope = TransactionScopeHelper.GetTran())
            {
                var data = usersService.AddEntity(user);
                //if (data.WorkTypeID != null)
                //{
                //    AdddRelationUserWorkType(data.ID, Convert.ToInt32(data.WorkTypeID));
                //}
                transactionScope.Complete();
                success = data != null;
            }

            return(Json(new Result(success, ResultType.Add), JsonRequestBehavior.AllowGet));
        }