public object DeleteUserGroup(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg  = string.Empty;
                string groupId = dicParas.ContainsKey("groupId") ? dicParas["groupId"].ToString() : string.Empty;

                //验证参数
                if (string.IsNullOrEmpty(groupId))
                {
                    errMsg = "工作组Id不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_UserGroupService base_UserGroupService = BLLContainer.Resolve <IBase_UserGroupService>();
                        var base_UserGroup = base_UserGroupService.GetModels(p => p.ID.ToString().Equals(groupId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserGroup>();
                        if (base_UserGroup == null)
                        {
                            errMsg = "该工作组不存在";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (!base_UserGroupService.Delete(base_UserGroup))
                        {
                            errMsg = "更新数据库失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        var dbContext             = DbContextFactory.CreateByModelNamespace(typeof(Base_UserGroup_Grant).Namespace);
                        var base_UserGroup_Grants = dbContext.Set <Base_UserGroup_Grant>().Where(p => p.GroupID.ToString().Equals(groupId, StringComparison.OrdinalIgnoreCase)).ToList();
                        foreach (var base_UserGroup_Grant in base_UserGroup_Grants)
                        {
                            dbContext.Entry(base_UserGroup_Grant).State = EntityState.Deleted;
                        }

                        if (dbContext.SaveChanges() < 0)
                        {
                            errMsg = "更新数据库失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
        public object AddUserGroup(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string logId  = string.Empty;

                XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel];

                if (userTokenKeyModel.LogType == (int)RoleType.MerchUser)
                {
                    logId = userTokenKeyModel.DataModel.MerchID;
                }

                string   groupName       = dicParas.ContainsKey("groupName") ? dicParas["groupName"].ToString() : string.Empty;
                string   note            = dicParas.ContainsKey("note") ? dicParas["note"].ToString() : string.Empty;
                object[] userGroupGrants = dicParas.ContainsKey("userGroupGrants") ? (object[])dicParas["userGroupGrants"] : null;

                //验证参数
                if (string.IsNullOrEmpty(groupName))
                {
                    errMsg = "工作组名称不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(groupName) && groupName.Length > 50)
                {
                    errMsg = "工作组名称不能超过50字";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(note) && note.Length > 500)
                {
                    errMsg = "工作组描述不能超过500字";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_UserGroupService base_UserGroupService = BLLContainer.Resolve <IBase_UserGroupService>();
                        var base_UserGroup = new Base_UserGroup {
                            GroupName = groupName, MerchID = logId, Note = note
                        };
                        if (!base_UserGroupService.Add(base_UserGroup))
                        {
                            errMsg = "更新数据库失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (userGroupGrants != null && userGroupGrants.Count() > 0)
                        {
                            var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_UserGroup_Grant).Namespace);
                            foreach (IDictionary <string, object> el in userGroupGrants)
                            {
                                if (el != null)
                                {
                                    var    dicPara              = new Dictionary <string, object>(el, StringComparer.OrdinalIgnoreCase);
                                    string functionId           = dicPara.ContainsKey("functionId") ? dicPara["functionId"].ToString() : string.Empty;
                                    string isAllow              = dicPara.ContainsKey("isAllow") ? dicPara["isAllow"].ToString() : string.Empty;
                                    var    base_UserGroup_Grant = new Base_UserGroup_Grant {
                                        FunctionID = Convert.ToInt32(functionId), GroupID = base_UserGroup.ID, IsAllow = !string.IsNullOrEmpty(isAllow) ? Convert.ToInt32(isAllow) : default(int?)
                                    };
                                    dbContext.Entry(base_UserGroup_Grant).State = EntityState.Added;
                                }
                                else
                                {
                                    errMsg = "提交数据包含空对象";
                                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                }
                            }

                            if (dbContext.SaveChanges() < 0)
                            {
                                errMsg = "更新数据库失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
        public object EditUserGroup(Dictionary <string, object> dicParas)
        {
            try
            {
                string   errMsg          = string.Empty;
                string   groupId         = dicParas.ContainsKey("groupId") ? dicParas["groupId"].ToString() : string.Empty;
                string   groupName       = dicParas.ContainsKey("groupName") ? dicParas["groupName"].ToString() : string.Empty;
                string   note            = dicParas.ContainsKey("note") ? dicParas["note"].ToString() : string.Empty;
                object[] userGroupGrants = dicParas.ContainsKey("userGroupGrants") ? (object[])dicParas["userGroupGrants"] : null;

                //验证参数
                if (string.IsNullOrEmpty(groupId))
                {
                    errMsg = "工作组Id不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(groupName))
                {
                    errMsg = "工作组名称不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(groupName) && groupName.Length > 50)
                {
                    errMsg = "工作组名称不能超过50字";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(note) && note.Length > 500)
                {
                    errMsg = "工作组描述不能超过500字";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_UserGroupService base_UserGroupService = BLLContainer.Resolve <IBase_UserGroupService>();
                        var base_UserGroup = base_UserGroupService.GetModels(p => p.ID.ToString().Equals(groupId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <Base_UserGroup>();
                        if (base_UserGroup == null)
                        {
                            errMsg = "该工作组不存在";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        base_UserGroup.GroupName = groupName;
                        base_UserGroup.Note      = note;
                        if (!base_UserGroupService.Update(base_UserGroup))
                        {
                            errMsg = "更新数据库失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (userGroupGrants != null && userGroupGrants.Count() >= 0)
                        {
                            var dbContext             = DbContextFactory.CreateByModelNamespace(typeof(Base_UserGroup_Grant).Namespace);
                            var base_UserGroup_Grants = dbContext.Set <Base_UserGroup_Grant>().Where(p => p.GroupID.ToString().Equals(groupId, StringComparison.OrdinalIgnoreCase)).ToList();
                            foreach (var base_UserGroup_Grant in base_UserGroup_Grants)
                            {
                                dbContext.Entry(base_UserGroup_Grant).State = EntityState.Deleted;
                            }

                            foreach (IDictionary <string, object> el in userGroupGrants)
                            {
                                if (el != null)
                                {
                                    var    dicPara              = new Dictionary <string, object>(el, StringComparer.OrdinalIgnoreCase);
                                    string functionId           = dicPara.ContainsKey("functionId") ? dicPara["functionId"].ToString() : string.Empty;
                                    string isAllow              = dicPara.ContainsKey("isAllow") ? dicPara["isAllow"].ToString() : string.Empty;
                                    var    base_UserGroup_Grant = new Base_UserGroup_Grant();
                                    base_UserGroup_Grant.FunctionID             = Convert.ToInt32(functionId);
                                    base_UserGroup_Grant.GroupID                = Convert.ToInt32(groupId);
                                    base_UserGroup_Grant.IsAllow                = Convert.ToInt32(isAllow);
                                    dbContext.Entry(base_UserGroup_Grant).State = EntityState.Added;
                                }
                                else
                                {
                                    errMsg = "提交数据包含空对象";
                                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                }
                            }

                            if (dbContext.SaveChanges() < 0)
                            {
                                errMsg = "更新数据库失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Exemple #4
0
        public object SaveUserInfo(Dictionary <string, object> dicParas)
        {
            string errMsg = string.Empty;
            int    userId, authorId;
            string workId     = dicParas.ContainsKey("workId") ? dicParas["workId"].ToString() : string.Empty;
            string state      = dicParas.ContainsKey("state") ? dicParas["state"].ToString() : string.Empty;
            string switchable = dicParas.ContainsKey("switchable") ? dicParas["switchable"].ToString() : string.Empty;
            string userType   = dicParas.ContainsKey("userType") ? dicParas["userType"].ToString() : string.Empty;
            string reason     = dicParas.ContainsKey("reason") ? dicParas["reason"].ToString() : string.Empty;
            string isAdmin    = dicParas.ContainsKey("isAdmin") ? dicParas["isAdmin"].ToString() : string.Empty;

            if (string.IsNullOrEmpty(state))
            {
                errMsg = "审核状态state参数不能为空";
                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
            }

            if (string.IsNullOrEmpty(userType))
            {
                errMsg = "用户类型userType参数不能为空";
                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
            }

            int iUserType = Convert.ToInt32(userType);

            if (state == ((int)WorkState.Pass).ToString()) //审核通过
            {
                if (!dicParas.ContainsKey("userGroup") || dicParas["userGroup"] == null)
                {
                    errMsg = "工作组userGroup参数不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!dicParas.ContainsKey("userGrant") || dicParas["userGrant"] == null)
                {
                    errMsg = "授权功能列表userGrant参数不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }
            }

            if (!checkParas(dicParas, out userId, out authorId, out errMsg))
            {
                LogHelper.SaveLog("错误:" + errMsg);
                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
            }

            //开启EF事务
            using (TransactionScope ts = new TransactionScope())
            {
                try
                {
                    if (state == ((int)WorkState.Pass).ToString()) //审核通过
                    {
                        //修改用户信息
                        Dictionary <string, object> userGroup             = new Dictionary <string, object>((IDictionary <string, object>)dicParas["userGroup"], StringComparer.OrdinalIgnoreCase);
                        IBase_UserGroupService      base_UserGroupService = BLLContainer.Resolve <IBase_UserGroupService>();
                        int ugid = Convert.ToInt32(userGroup["id"]);
                        if (!base_UserGroupService.Any(w => w.ID.Equals(ugid)))
                        {
                            errMsg = "工作组" + userGroup["groupName"] + "不存在";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>();
                        var base_UserInfo = userInfoService.GetModels(p => p.UserID.Equals(userId)).FirstOrDefault <Base_UserInfo>();
                        base_UserInfo.UserGroupID = ugid;
                        base_UserInfo.Auditor     = authorId;
                        base_UserInfo.AuditorTime = DateTime.Now;
                        base_UserInfo.Status      = (int)UserStatus.Pass;
                        base_UserInfo.IsAdmin     = !string.IsNullOrEmpty(isAdmin) ? Convert.ToInt32(isAdmin) : (int?)null;
                        base_UserInfo.UserType    = Convert.ToInt32(userType);
                        base_UserInfo.Switchable  = !string.IsNullOrEmpty(switchable) ? Convert.ToInt32(switchable) : (int?)null;

                        string storeId = base_UserInfo.StoreID;
                        if (base_UserInfo.IsAdmin == 1 && userInfoService.Any(a => a.UserID != userId && a.IsAdmin == 1 && a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)))
                        {
                            errMsg = "同一个门店只能有一个管理员";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (!userInfoService.Update(base_UserInfo))
                        {
                            errMsg = "修改用户信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        //添加或修改授权功能表
                        var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_UserGrant).Namespace);
                        var userGrant = (object[])dicParas["userGrant"];
                        foreach (IDictionary <string, object> iUgr in userGrant)
                        {
                            if (iUgr != null)
                            {
                                var ugr   = new Dictionary <string, object>(iUgr, StringComparer.OrdinalIgnoreCase);
                                int ugrid = Convert.ToInt32(ugr["id"]);
                                if (!dbContext.Set <Base_UserGrant>().Any(w => w.GrantID.Value.Equals(ugrid) && w.UserID.Value.Equals(userId)))
                                {
                                    var base_UserGrant = new Base_UserGrant();
                                    base_UserGrant.GrantID = ugrid;
                                    base_UserGrant.UserID  = userId;
                                    base_UserGrant.GrantEN = Convert.ToInt32(ugr["grantEn"]);
                                    dbContext.Entry(base_UserGrant).State = EntityState.Added;
                                }
                                else
                                {
                                    var base_UserGrant = dbContext.Set <Base_UserGrant>().Where(p => p.GrantID == ugrid && p.UserID == userId).FirstOrDefault();
                                    base_UserGrant.GrantEN = Convert.ToInt32(ugr["grantEn"]);
                                    dbContext.Entry(base_UserGrant).State = EntityState.Modified;
                                }
                            }
                        }

                        if (dbContext.SaveChanges() < 0)
                        {
                            errMsg = "保存授权功能失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        //修改工单
                        IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>();
                        var xC_WorkInfo = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XC_WorkInfo>();
                        xC_WorkInfo.AuditorID = authorId;
                        xC_WorkInfo.AuditTime = DateTime.Now;
                        xC_WorkInfo.WorkState = (int)WorkState.Pass;
                        xC_WorkInfo.AuditBody = "审核通过";
                        xC_WorkInfo.WorkType  = (int)WorkType.UserCheck;
                        if (!xC_WorkInfoService.Update(xC_WorkInfo))
                        {
                            errMsg = "修改工单失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        //添加日志
                        ILog_OperationService log_OperationService = BLLContainer.Resolve <ILog_OperationService>();
                        var log_Operation = new Log_Operation();
                        log_Operation.UserID   = userId;
                        log_Operation.AuthorID = authorId;
                        log_Operation.Content  = "审核通过";
                        if (!log_OperationService.Add(log_Operation))
                        {
                            errMsg = "添加日志失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }
                    }
                    else if (state == ((int)WorkState.Reject).ToString()) //审核拒绝
                    {
                        //修改工单
                        IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>();
                        var xC_WorkInfo = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault <XC_WorkInfo>();
                        xC_WorkInfo.AuditorID = authorId;
                        xC_WorkInfo.AuditTime = DateTime.Now;
                        xC_WorkInfo.WorkState = (int)WorkState.Reject;
                        xC_WorkInfo.AuditBody = "拒绝理由:" + reason;
                        xC_WorkInfo.WorkType  = (int)WorkType.UserCheck;
                        if (!xC_WorkInfoService.Update(xC_WorkInfo))
                        {
                            errMsg = "修改工单失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        //添加日志
                        ILog_OperationService log_OperationService = BLLContainer.Resolve <ILog_OperationService>();
                        var log_Operation = new Log_Operation();
                        log_Operation.UserID   = userId;
                        log_Operation.AuthorID = authorId;
                        log_Operation.Content  = "拒绝理由:" + reason;
                        if (!log_OperationService.Add(log_Operation))
                        {
                            errMsg = "添加日志失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }
                    }
                    else
                    {
                        errMsg = "不明确的审核状态";
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }

                    ts.Complete();
                    return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
                }
                catch (Exception ex)
                {
                    LogHelper.SaveLog("错误:" + ex.Message);
                    return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                }
            }
        }