Пример #1
0
        public IActionResult AddJobType(string job_name)
        {
            ErrorRequestData err = null;

            if (string.IsNullOrWhiteSpace(job_name))
            {
                err = new ErrorRequestData()
                {
                    HttpStatusCode = 401, ErrorMessage = "参数错误"
                };
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }
            try
            {
                job_type jt = new job_type()
                {
                    job_name = job_name, addtime = DateTime.Now, user_id = signedUser.user_uuid, uuid = UUID.getUUID()
                };
                dbContext.job_type.Add(jt);
                dbContext.SaveChanges();
                var list = dbContext.job_type.Where(x => x.user_id.Equals(signedUser.user_uuid)).ToList();
                return(Json(list));
            }
            catch (DbUpdateException dbex)
            {
                if (dbex.InnerException is PostgresException npge)
                {
                    err = new ErrorRequestData()
                    {
                        HttpStatusCode = 500, ErrorMessage = npge.Detail
                    };
                }
                else
                {
                    err = new ErrorRequestData()
                    {
                        HttpStatusCode = 500, ErrorMessage = dbex.Message
                    };
                }
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }
            catch (Exception ex)
            {
                err = new ErrorRequestData()
                {
                    HttpStatusCode = 500, ErrorMessage = ex.Message
                };
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }
        }
Пример #2
0
        /// <summary>
        /// 提交测试题答案
        /// </summary>
        /// <param name="job_id"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public IActionResult submit_exam_data(string job_id, List <user_answer> list)
        {
            ErrorRequestData err = null;

            if (list != null && list.Count > 0 && !string.IsNullOrWhiteSpace(job_id))
            {
                try
                {
                    var score = new user_score()
                    {
                        job_id = job_id, user_id = signedUser.user_uuid
                    };
                    var exam_dict = dbContext.exam_data.Where(x => x.job_id.Equals(job_id)).Select(x => new { x.id, x.exam_type, x.exam_cq_anwser }).ToDictionary(x => x.id);
                    list.ForEach(x =>
                    {
                        if (exam_dict.ContainsKey(x.exam_id))
                        {
                            if (x.exam_type.Equals("cq") && x.exam_answer.Equals(exam_dict[x.exam_id].exam_cq_anwser))
                            {
                                ++score.cq_score;
                            }
                            x.id            = UUID.getUUID();
                            x.user_score_id = score.id;
                            dbContext.user_answer.Add(x);
                        }
                    });
                    dbContext.user_score.Add(score);
                    dbContext.SaveChanges();
                    return(Content("提交成功"));
                }
                catch (DbUpdateException dbex)
                {
                    if (dbex.InnerException is PostgresException npge)
                    {
                        err = new ErrorRequestData()
                        {
                            HttpStatusCode = 500, ErrorMessage = npge.Detail
                        };
                    }
                    else
                    {
                        err = new ErrorRequestData()
                        {
                            HttpStatusCode = 500, ErrorMessage = dbex.Message
                        };
                    }
                    return(new ContentResult()
                    {
                        StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                    });
                }
                catch (Exception ex)
                {
                    err = new ErrorRequestData()
                    {
                        HttpStatusCode = 500, ErrorMessage = ex.Message
                    };
                    return(new ContentResult()
                    {
                        StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                    });
                }
            }
            else
            {
                err = new ErrorRequestData()
                {
                    HttpStatusCode = 401, ErrorMessage = nameof(job_id) + "或" + nameof(list) + "参数错误"
                };
                return(new ContentResult()
                {
                    Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType, StatusCode = err.HttpStatusCode
                });
            }
        }
Пример #3
0
        /// <summary>
        /// 注册用户的方法
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public IActionResult RegisterUser(recruit_user user)
        {
            ErrorRequestData err = null;

            if (user == null || string.IsNullOrWhiteSpace(user.pwd))
            {
                err = new ErrorRequestData()
                {
                    HttpStatusCode = 401, ErrorMessage = "参数错误"
                };
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }

            try
            {
                user.pwd = Sha1.getSha1String(user.pwd);
                if ("user".Equals(user.auth_role))
                {
                    if (string.IsNullOrWhiteSpace(user.uname) || string.IsNullOrWhiteSpace(user.birthday))
                    {
                        err = new ErrorRequestData()
                        {
                            HttpStatusCode = 401, ErrorMessage = "参数错误"
                        };
                        return(new ContentResult()
                        {
                            StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                        });
                    }
                    dbContext.recruit_user.Add(user);
                    dbContext.SaveChanges();
                    return(Content("请求成功"));
                }
                else if ("company".Equals(user.auth_role))
                {
                    if (string.IsNullOrWhiteSpace(user.company_address) ||
                        string.IsNullOrWhiteSpace(user.company_code) ||
                        string.IsNullOrWhiteSpace(user.company_contact) ||
                        string.IsNullOrWhiteSpace(user.company_name))
                    {
                        err = new ErrorRequestData()
                        {
                            HttpStatusCode = 401, ErrorMessage = "参数错误"
                        };
                        return(new ContentResult()
                        {
                            StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                        });
                    }
                    dbContext.recruit_user.Add(user);
                    dbContext.SaveChanges();
                    return(Content("请求成功"));
                }
            }
            catch (DbUpdateException dbex)
            {
                if (dbex.InnerException is PostgresException npge)
                {
                    err = new ErrorRequestData()
                    {
                        HttpStatusCode = 500, ErrorMessage = npge.Detail
                    };
                }
                else
                {
                    err = new ErrorRequestData()
                    {
                        HttpStatusCode = 500, ErrorMessage = dbex.Message
                    };
                }
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }
            catch (Exception ex)
            {
                err = new ErrorRequestData()
                {
                    HttpStatusCode = 500, ErrorMessage = ex.Message
                };
                return(new ContentResult()
                {
                    StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
                });
            }

            err = new ErrorRequestData()
            {
                HttpStatusCode = 401, ErrorMessage = "注册失败"
            };
            return(new ContentResult()
            {
                StatusCode = err.HttpStatusCode, Content = err.toJosnString(), ContentType = ConstantTypeString.JsonContentType
            });
        }