Exemplo n.º 1
0
 public AgencyDTO(Agency agency)
 {
     this.ID = agency.ID;
     this.Name = agency.Name;
     this.State = agency.State;
     this.RegTime = agency.RegTime;
     this.AddTime = agency.AddTime;
 }
Exemplo n.º 2
0
 public UserDTO(User user, Agency agency)
     : this(user)
 {
     this.Agency = agency;
 }
Exemplo n.º 3
0
        /// <summary>
        /// 使用默认配置初始化机构信息,返回添加成功后的机构主键ID
        /// </summary>
        public int Insert(Agency agency, AgencyAdmin admin)
        {
            // 1.添加机构信息
            // 2.添加机构管理员信息
            // 3.添加机构创建者
            // 4.添加机构默认配置信息
            // 5.添加机构课程章节信息

            int agencyID = 0;

            const string insert_agency_sql = @"INSERT INTO Agency(Name, RegTime) VALUES (@Name, @RegTime);SELECT LAST_INSERT_ID();";

            const string insert_agency_admin_sql = @"INSERT INTO AgencyAdmin(AgencyID, ChineseName, Phone, Password,  Level)
                                                   VALUES (@AgencyID, @ChineseName, @Phone, @Password, @Level);
                                                   SELECT LAST_INSERT_ID();";

            const string insert_agency_creator_sql = @"INSERT INTO AgencyCreator(AgencyID, AdminID) VALUES (@AgencyID, @AdminID);";

            const string insert_agency_config_sql = @"INSERT INTO AgencyConfig(AgencyID) VALUES (@AgencyID);";

            const string insert_agency_course_sql = @"INSERT INTO Course(AgencyID, Name, Code, Duration, Description)
                                                    VALUES (@AgencyID, @Name, @Code, @Duration, @Description);
                                                    SELECT LAST_INSERT_ID();";

            const string insert_agency_chapter_sql = @"INSERT INTO Chapter(CourseID, ChapterIndex, Name) VALUES (@CourseID, @ChapterIndex, @Name);";

            using (DbConnection connection = ConnectionManager.OpenConnection)
            {
                IDbTransaction transaction = connection.BeginTransaction();
                try
                {
                    // 添加机构信息
                    agencyID = connection.Query<int>(insert_agency_sql, agency, transaction).SingleOrDefault<int>();

                    // 初始化管理员账号及创建者信息
                    admin.AgencyID = agencyID;
                    int adminID = connection.Query<int>(insert_agency_admin_sql, admin, transaction).SingleOrDefault<int>();
                    connection.Execute(insert_agency_creator_sql, new { AgencyID = agencyID, AdminID = adminID }, transaction);

                    // 初始化机构默认配置选项
                    connection.Execute(insert_agency_config_sql, new { AgencyID = agencyID }, transaction);

                    // 初始化课程及章节信息
                    List<SysCourse> sysCourses = sysCourseDAL.GetAll();
                    if (sysCourses != null)
                    {
                        foreach (var sysCourse in sysCourses)
                        {
                            // 插入课程
                            int courseID = connection.Query<int>(
                                insert_agency_course_sql,
                                new { AgencyID = agencyID, Name = sysCourse.Name, Code = sysCourse.Code, Duration = sysCourse.Duration, Description = sysCourse.Description },
                                transaction).SingleOrDefault<int>();

                            // 插入章节
                            List<SysChapter> sysChapters = sysChapterDAL.GetByCourseID(sysCourse.ID);
                            if (sysChapters != null)
                            {
                                foreach (var sysChapter in sysChapters)
                                {
                                    connection.Execute(insert_agency_chapter_sql, new { CourseID = courseID, ChapterIndex = sysChapter.ChapterIndex, Name = sysChapter.Name }, transaction);
                                }
                            }
                        }
                    }

                    // 提交事务
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw ex;
                }

                return agencyID;
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// 更新实体信息
 /// </summary>
 public void Update(Agency agency)
 {
     const string sql = @"UPDATE Agency SET Name = @Name, State= @State WHERE IsDeleted = 0 AND ID = @ID";
     using (DbConnection connection = ConnectionManager.OpenConnection)
     {
         connection.Execute(sql, agency);
     }
 }
Exemplo n.º 5
0
        /// <summary>
        /// 添加通话记录
        /// </summary>
        private HttpResponseMessage AddCallRecord(HttpRequestMessage request)
        {
            log.Debug(Constant.DEBUG_START);

            string sign = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_SIGN);
            string cmd = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_CMD);
            string random = ApiQueryUtil.QueryHeader(Constant.HTTP_HEADER_RANDOM);

            string userIDString = ApiQueryUtil.QueryArgByPost("user_id");
            string timeString = ApiQueryUtil.QueryArgByPost("time");
            string duration = ApiQueryUtil.QueryArgByPost("duration");
            string typeString = ApiQueryUtil.QueryArgByPost("type");
            string number = ApiQueryUtil.QueryArgByPost("number");
            string name = ApiQueryUtil.QueryArgByPost("name");

            Dictionary<string, string> args = new Dictionary<string, string>()
            {
                { Constant.HTTP_HEADER_CMD, cmd },
                { Constant.HTTP_HEADER_RANDOM, random },
                { "user_id", userIDString },
                { "time", timeString },
                { "duration", duration },
                { "type", typeString },
                { "number", number },
                { "name", name }
            }.OrderBy(element => element.Key).ToDictionary(o => o.Key, p => p.Value);

            ServiceInvokeDTO<CallRecordDTO> result = null;
            try
            {
                // Check sign
                if (securityService.CheckSign(args, Config.ApiSignSecretKey, sign))
                {
                    Agency callRecord = new Agency();
                    callRecord.UserID = Convert.ToInt32(userIDString);
                    callRecord.Time = Convert.ToDateTime(timeString);
                    callRecord.Duration = duration;
                    callRecord.Type = Convert.ToInt32(typeString);
                    callRecord.Number = number;
                    callRecord.Name = name;

                    result = userDataService.AddCallRecord(callRecord);

                    // 设置DTO数据中的录音文件下载地址
                    if (result != null && result.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                    {
                        CallRecordDTO dto = result.Data;
                        if (dto != null && dto.CallVoice != null)
                        {
                            dto.CallVoice.DownloadUrl = string.Format(Constant.CALLVOICE_DOWNLOAD_FORMAT,
                                request.Headers.Host, dto.CallVoice.FileSaveName);
                        }
                    }
                }
                else
                {
                    result = new ServiceInvokeDTO<CallRecordDTO>(InvokeCode.SYS_SIGN_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                result = new ServiceInvokeDTO<CallRecordDTO>(InvokeCode.SYS_INNER_ERROR);
            }
            log.Debug(Constant.DEBUG_END);

            return request.CreateResponse(HttpStatusCode.OK, result);
        }
Exemplo n.º 6
0
 public AgencyDTO(Agency agency, AgencyConfig config, int creatorID)
     : this(agency)
 {
     this.Config = config;
     this.CreatorID = creatorID;
 }
Exemplo n.º 7
0
        /// <summary>
        /// 注册培训机构
        /// </summary>
        public ServiceInvokeDTO AgencyReg(string phone, string captcha, string agencyName, string password)
        {
            log.Debug(Constant.DEBUG_START);
            ServiceInvokeDTO result = null;
            try
            {
                // 检测验证码
                ServiceInvokeDTO checkCaptchaResult = securityService.CheckCaptcha(CaptchaCodeType.RegCode, phone, captcha);
                if (checkCaptchaResult != null && checkCaptchaResult.Code == InvokeCode.SYS_INVOKE_SUCCESS)
                {
                    // 检测手机号是否注册
                    AgencyAdmin dbAdmin = agencyAdminDAL.GetByPhone(phone);
                    if (dbAdmin == null)
                    {
                        // 检测机构名称是否存在
                        Agency dbAgency = agencyDAL.GetByName(agencyName);
                        if (dbAgency == null)
                        {
                            Agency agency = new Agency();
                            agency.Name = agencyName;
                            agency.RegTime = DateTime.Now;

                            AgencyAdmin admin = new AgencyAdmin();
                            admin.ChineseName = agencyName;
                            admin.Phone = phone;
                            admin.Password = SecurityUtil.MD5(password + Constant.ADMIN_SALT_KEY);
                            admin.Level = AdminLevel.AgencyCreatorAdmin;

                            // 验证参数
                            AgencyValidator validator = new AgencyValidator();
                            ValidationResult validatorResult = validator.Validate(agency);
                            if (validatorResult.IsValid)
                            {
                                agencyDAL.Insert(agency, admin);
                                result = new ServiceInvokeDTO(InvokeCode.SYS_INVOKE_SUCCESS);
                            }
                            else
                            {
                                result = new ServiceInvokeDTO(InvokeCode.SYS_ARG_ERROR);
                                log.Error(string.Format(Constant.DEBUG_ARG_ERROR_FORMATER, validatorResult.Errors[0].ErrorMessage));
                            }
                        }
                        else
                        {
                            result = new ServiceInvokeDTO(InvokeCode.AGENCY_NAME_EXIST_ERROR);
                        }
                    }
                    else
                    {
                        result = new ServiceInvokeDTO(InvokeCode.SMS_PHONE_EXIST_WHEN_REG);
                    }
                }
                else
                {
                    result = new ServiceInvokeDTO(InvokeCode.SYS_CAPTCHA_ERROR);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw ex;
            }
            log.Debug(Constant.DEBUG_END);

            return result;
        }