Exemple #1
0
        private void ValidateInputs(GridViewRow row)
        {
            var txtTitle       = row.FindControl("txtTitle") as TextBox;
            var txtFirstName   = row.FindControl("txtFirstName") as TextBox;
            var txtLastName    = row.FindControl("txtLastName") as TextBox;
            var txtDateOfBirth = row.FindControl("txtDateOfBirth") as TextBox;
            var ddlGender      = row.FindControl("ddlGender") as DropDownList;

            ValidationMessages.Clear();

            if (string.IsNullOrWhiteSpace(txtTitle.Text))
            {
                ValidationMessages.Add("'Title' is a required field");
            }

            if (string.IsNullOrWhiteSpace(txtLastName.Text))
            {
                ValidationMessages.Add("'Last Name' is a required field");
            }

            DateTime result;

            if (string.IsNullOrWhiteSpace(txtDateOfBirth.Text))
            {
                ValidationMessages.Add("'Date Of Birth' is a required field");
            }
            else if (!DateTime.TryParse(txtDateOfBirth.Text, out result))
            {
                ValidationMessages.Add("'Date Of Birth' is not a valid date");
            }

            int selectedGenderId;

            if (!int.TryParse(ddlGender.SelectedValue, out selectedGenderId))
            {
                ValidationMessages.Add("'Gender' is a required field");
            }
            ;

            if (!Genders.Any(x => x.Id == selectedGenderId))
            {
                ValidationMessages.Add("'Gender' is a required field");
            }
        }
Exemple #2
0
        private void PopulateGenderDropDownList(GridViewRow row)
        {
            var ddlGender = row.FindControl("ddlGender") as DropDownList;

            if (ddlGender == null)
            {
                return;
            }

            if (!Genders.Any())
            {
                LoadGenderList();
            }

            ddlGender.DataSource     = Genders;
            ddlGender.DataValueField = "Id";
            ddlGender.DataTextField  = "Name";
            ddlGender.DataBind();
            ddlGender.Items.Insert(0, new ListItem("--Select--", "0"));
        }
Exemple #3
0
        public NpgsqlDbContext(DbContextOptions options) : base(options)
        {
            Database.EnsureCreated();

            if (!Genders.Any())
            {
                var male = new Gender {
                    Name = "Мужской"
                };
                var female = new Gender {
                    Name = "Женский"
                };
                var other = new Gender {
                    Name = "Другой"
                };

                Genders.AddRange(new[] { male, female, other });
                SaveChanges();
            }
        }