示例#1
0
        private bool checkParas(Dictionary <string, object> dicParas, out int userId, out int authorId, out string errMsg)
        {
            errMsg   = string.Empty;
            userId   = 0;
            authorId = 0;

            try
            {
                string workId = dicParas.ContainsKey("workId") ? dicParas["workId"].ToString() : string.Empty;

                if (string.IsNullOrEmpty(workId))
                {
                    errMsg = "工单号workId参数不能为空";
                    return(false);
                }

                //验证工单
                IXC_WorkInfoService xC_WorkInfoService = BLLContainer.Resolve <IXC_WorkInfoService>();
                var xC_WorkInfoList  = xC_WorkInfoService.GetModels(p => p.WorkID.ToString().Equals(workId, StringComparison.OrdinalIgnoreCase));
                int xC_WorkInfoCount = xC_WorkInfoList.Count <XC_WorkInfo>();
                if (xC_WorkInfoCount == 0)
                {
                    errMsg = "工单号" + workId + "不存在";
                    return(false);
                }

                //验证用户
                var xC_WorkInfo = xC_WorkInfoList.FirstOrDefault <XC_WorkInfo>();
                IBase_UserInfoService userInfoService = BLLContainer.Resolve <IBase_UserInfoService>();
                var userList = userInfoService.GetModels(p => p.UserID.Equals(xC_WorkInfo.SenderID.Value));
                if (userList.Count <Base_UserInfo>() == 0)
                {
                    errMsg = "工单号" + workId + "的用户ID不存在";
                    return(false);
                }

                userId = userList.FirstOrDefault <Base_UserInfo>().UserID;

                //验证审核人
                userList = userInfoService.GetModels(p => p.UserID.Equals(xC_WorkInfo.AuditorID.Value));
                if (userList.Count <Base_UserInfo>() == 0)
                {
                    errMsg = "工单号" + workId + "的审核人ID不存在";
                    return(false);
                }

                authorId = userList.FirstOrDefault <Base_UserInfo>().UserID;

                return(true);
            }
            catch (Exception e)
            {
                errMsg = e.Message;
                return(false);
            }
        }
示例#2
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));
                }
            }
        }