コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string action = Request["action"];
            string json   = string.Empty;

            try
            {
                switch (action)
                {
                case "checkName":
                    string    name = Request["name"];
                    DataTable dt   = RegisterDal.CheckName(name);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        json = "1";
                    }
                    else
                    {
                        json = "0";
                    }
                    break;

                case "register":
                    string OrgID          = Request["OrgID"];
                    string Token          = Request["Token"];
                    string AppID          = Request["AppID"];
                    string EncodingAESKey = Request["EncodingAESKey"];
                    string UserName       = Request["UserName"];
                    string Password       = Request["Password"];
                    string AppSecret      = Request["AppSecret"];
                    int    rowcount       = RegisterDal.Register(OrgID, Token, AppID, EncodingAESKey, UserName, Password, AppSecret);
                    if (rowcount == 1)
                    {
                        json = "1";
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception)
            {
                throw;
            }
            if (!string.IsNullOrEmpty(json))
            {
                Response.Write(json);
                Response.End();
            }
        }
コード例 #2
0
        public object Post([FromBody] RegisterDal body)
        {
            if (HttpContext.Request.ContentType != "application/json")
            {
                return(StatusCode(406, new ErrorResult()
                {
                    Result = 406, ErrMessage = "ContentType should be 'application/json'"
                }));
            }

            var apiKey = StringHelper.RandomString(16);

            using (var context = new AXAExamSampleDBContext()) {
                var existApplicant = context.Applicants.Where(o => o.Email == body.Email).FirstOrDefault();
                if (existApplicant != null)
                {
                    if (existApplicant.Id != 0)
                    {
                        return(StatusCode(200, new SuccessResult()
                        {
                            Result = 200,
                            Message = $"Thank you for registering! Your x-axa-api-key is: {existApplicant.XaxaApiKey}"
                        }));
                    }
                }

                var applicant = new Applicants()
                {
                    Name            = body.Name,
                    Email           = body.Email,
                    Mobile          = body.Mobile,
                    PositionApplied = body.PositionApplied,
                    Source          = body.Source,
                    XaxaApiKey      = apiKey
                };

                context.Applicants.Add(applicant);
                context.SaveChanges();
            }

            return(StatusCode(200, new SuccessResult()
            {
                Result = 200,
                Message = $"Thank you for registering! Your x-axa-api-key is: {apiKey}"
            }));
        }