Esempio n. 1
0
        public async Task <ModelResponseMessageRegisterActive> AddRegisterActiveAsync(ModelRegisterActive model)
        {
            ModelResponseMessageRegisterActive resp = new ModelResponseMessageRegisterActive();

            EntityRegisterUser entity_model = new EntityRegisterUser();

            entity_model.register_id   = Encoding.UTF8.GetString(Convert.FromBase64String(model.registerid));
            entity_model.first_name_1  = model.firstname1;
            entity_model.first_name_2  = model.firstname2;
            entity_model.first_name    = model.firstname;
            entity_model.full_name     = model.fullname;
            entity_model.position      = model.position;
            entity_model.work_phone    = model.workphone;
            entity_model.faculty       = model.faculty;
            entity_model.mobile        = model.mobile;
            entity_model.fax           = model.fax;
            entity_model.education     = model.education;
            entity_model.character     = model.character;
            entity_model.note1         = model.note1;
            entity_model.note2         = model.note2;
            entity_model.note3         = model.note3;
            entity_model.confirm_date  = DateTime.Now;
            entity_model.member_expire = DateTime.Now.AddYears(10);

            resp = await _IRegisterUserRepository.AddRegisterActiveAsync(entity_model);

            return(resp);
        }
        public async Task <ModelResponseMessageRegisterActive> AddRegisterActiveAsync(EntityRegisterUser model)
        {
            ModelResponseMessageRegisterActive resp = new ModelResponseMessageRegisterActive();

            using (SqlConnection conn = new SqlConnection(ConnectionString))
            {
                conn.Open();
                using (SqlCommand cmd = new SqlCommand("sp_register_active", conn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.Add("@RegisterId", SqlDbType.VarChar, 100).Value = model.register_id;
                    cmd.Parameters.Add("@FirstName1", SqlDbType.VarChar, 50).Value  = ParseDataHelper.ConvertDBNull(model.first_name_1);
                    cmd.Parameters.Add("@FirstName2", SqlDbType.VarChar, 50).Value  = ParseDataHelper.ConvertDBNull(model.first_name_2);
                    cmd.Parameters.Add("@FirstName", SqlDbType.VarChar, 50).Value   = ParseDataHelper.ConvertDBNull(model.first_name);
                    cmd.Parameters.Add("@FullName", SqlDbType.VarChar, 200).Value   = ParseDataHelper.ConvertDBNull(model.full_name);
                    cmd.Parameters.Add("@Position", SqlDbType.VarChar, 2).Value     = ParseDataHelper.ConvertDBNull(model.position);
                    cmd.Parameters.Add("@Faculty", SqlDbType.VarChar, 2).Value      = ParseDataHelper.ConvertDBNull(model.faculty);
                    cmd.Parameters.Add("@WorkPhone", SqlDbType.VarChar, 50).Value   = ParseDataHelper.ConvertDBNull(model.work_phone);
                    cmd.Parameters.Add("@Mobile", SqlDbType.VarChar, 20).Value      = ParseDataHelper.ConvertDBNull(model.mobile);
                    cmd.Parameters.Add("@Fax", SqlDbType.VarChar, 20).Value         = ParseDataHelper.ConvertDBNull(model.fax);
                    cmd.Parameters.Add("@Education", SqlDbType.VarChar, 2).Value    = model.education;
                    cmd.Parameters.Add("@Character", SqlDbType.VarChar, 2).Value    = model.character;
                    cmd.Parameters.Add("@Note1", SqlDbType.NVarChar).Value          = ParseDataHelper.ConvertDBNull(model.note1);
                    cmd.Parameters.Add("@Note2", SqlDbType.NVarChar).Value          = ParseDataHelper.ConvertDBNull(model.note2);
                    cmd.Parameters.Add("@Note3", SqlDbType.NVarChar).Value          = ParseDataHelper.ConvertDBNull(model.note3);
                    cmd.Parameters.Add("@ConfirmDate", SqlDbType.DateTime).Value    = model.confirm_date;
                    cmd.Parameters.Add("@MemberExpire", SqlDbType.DateTime).Value   = model.member_expire;

                    SqlParameter rStatus = cmd.Parameters.Add("@rStatus", SqlDbType.Int);
                    rStatus.Direction = ParameterDirection.Output;
                    SqlParameter rMessage = cmd.Parameters.Add("@rMessage", SqlDbType.NVarChar, 500);
                    rMessage.Direction = ParameterDirection.Output;

                    await cmd.ExecuteNonQueryAsync();

                    if ((int)cmd.Parameters["@rStatus"].Value > 0)
                    {
                        resp.Status = true;
                    }
                    else
                    {
                        resp.Message = (string)cmd.Parameters["@rMessage"].Value;
                    }
                }
                conn.Close();
            }
            return(resp);
        }
        public async Task <IActionResult> RegisterActive([FromBody] ModelRegisterActive model)
        {
            IActionResult _result = BadRequest();

            CancellationTokenSource source = new CancellationTokenSource();

            var tasks = Task.Run(async delegate
            {
                ModelResponseMessageRegisterActive e = await _IRegisterUserService.AddRegisterActiveAsync(model);

                if (e.Status == true)
                {
                    _result = Ok(e);

                    string serverip = Encoding.UTF8.GetString(Convert.FromBase64String(_EnvironmentConfig.Server));

                    string register_id = Encoding.UTF8.GetString(Convert.FromBase64String(model.registerid));

                    string linkactive = $"{serverip}/{"efilling/log_in"}";

                    string mail_body = "<h3>คุณได้ลงทะเบียนเสร็จสิ้นตามขั้นตอนแล้ว</h3>" + Environment.NewLine +
                                       "<h2>อ้างอิงหมายเลข " + register_id + "</h2>" + Environment.NewLine +
                                       "<h4>ทั้งนี้คุณสามารถเข้าใช้งานระบบ ขอให้ท่านสนุกกับการใช้งาน! <a href='" + linkactive + "'>คลิ้กเพื่อเข้าสู่ระบบ</a>.</h4>";

                    await _EmailHelper.SentGmail(model.email, "eFilling : แจ้งผลการยืนยันลงทะเบียน", mail_body, "");
                }
                return(_result);
            });

            source.Cancel();
            try
            {
                tasks.Wait();
            }
            catch (AggregateException ae)
            {
                foreach (var e in ae.InnerExceptions)
                {
                    Console.WriteLine("{0}: {1}", e.GetType().Name, e.Message);
                }
            }
            if (tasks.Status == TaskStatus.RanToCompletion)
            {
                source.Dispose();
            }

            return(_result);
        }