Exemplo n.º 1
0
        protected async void btnRegister_Onclick(object sender, EventArgs e)
        {
            try
            {
                var senior = new SeniorsModel()
                {
                    SeniorID       = txtseniorID.Text,
                    FirstName      = txtfirstname.Text,
                    MiddleName     = txtmiddlename.Text,
                    LastName       = txtlastname.Text,
                    Gender         = rblGender.SelectedItem.Value,
                    DOB            = Convert.ToDateTime(txtDob.Text, CultureInfo.InvariantCulture),
                    MaritialStatus = rblMS.SelectedItem.Value,
                    ContactNum     = txtcontactnum.Text,
                    Religion       = txtreligion.Text,
                    Occupation     = txtoccupation.Text,
                    Barangay       = txtbarangay.Text,
                    Municipality   = txtmunicipality.Text,
                    Province       = txtprovince.Text,
                    Photo          = fuPhoto.FileBytes
                };
                await SeniorsRepository.InsertSeniorAsync(senior);

                Response.Write(@"<script>alert('Record Successfully Created!');</script>");
                ResetForm();
            }
            catch (Exception exception)
            {
                Response.Write($@"<script>alert('${exception.Message}');</script>");
            }
        }
 public static async Task <int> InsertSeniorAsync(SeniorsModel model)
 {
     using (IDbConnection connection = new MySqlConnection(DBConnectionString.GetConnectionString()))
     {
         string query      = @"insert into seniors (SeniorId, FirstName, MiddleName, LastName, Gender, DOB, MaritialStatus, ContactNum, Religion, Occupation, Barangay, Municipality, Province, Photo) values (@SeniorID, upper(@FirstName), upper(@MiddleName), upper(@LastName), @Gender, @DOB, @MaritialStatus, @ContactNum, @Religion, @Occupation, upper(@Barangay), upper(@Municipality), upper(@Province), @Photo)";
         var    parameters = new DynamicParameters();
         parameters.Add("SeniorID", model.SeniorID, DbType.Int32);
         parameters.Add("FirstName", model.FirstName, DbType.String);
         parameters.Add("MiddleName", model.MiddleName, DbType.String);
         parameters.Add("LastName", model.LastName, DbType.String);
         parameters.Add("Gender", model.Gender, DbType.String);
         parameters.Add("DOB", model.DOB, DbType.Date);
         parameters.Add("MaritialStatus", model.MaritialStatus, DbType.String);
         parameters.Add("ContactNum", model.ContactNum, DbType.String);
         parameters.Add("Religion", model.Religion, DbType.String);
         parameters.Add("Occupation", model.Occupation, DbType.String);
         parameters.Add("Barangay", model.Barangay, DbType.String);
         parameters.Add("Municipality", model.Municipality, DbType.String);
         parameters.Add("Province", model.Province, DbType.String);
         parameters.Add("Photo", model.Photo, DbType.Binary);
         return(await connection.ExecuteAsync(query, parameters));
     }
 }