Exemplo n.º 1
0
        public int Update(FamilyUpdateModel model)
        {
            _adoNetDbHelper.command = _adoNetDbHelper.connection.CreateCommand();

            _adoNetDbHelper.command.CommandText =
                $"UPDATE {TableName} SET TC=@newTCNo, Citizenship=@citizenship,Name=@name, Surname=@surname, BirthDate=@birthDate, PlaceOfBirth=@placeOfBirth, Gender=@gender, JobState=@jobState, JobDescription=@jobDescription,Reference=@reference, Salary=@salary, MobilePhone=@mobilePhone, HomePhone=@homePhone, MotherName=@motherName, FatherName=@fatherName, isMarried=@isMarried, EducationalStatus=@educationalStatusId, SocialSecurityId=@socialSecurityId, FamilyId=@familyId WHERE Id={model.Person.Id}";

            _adoNetDbHelper.command.Parameters.AddWithValue("@newTCNo", model.Person.TC);
            _adoNetDbHelper.command.Parameters.AddWithValue("@citizenship", model.Person.Citizenship);
            _adoNetDbHelper.command.Parameters.AddWithValue("@name", model.Person.Name);
            _adoNetDbHelper.command.Parameters.AddWithValue("@surname", model.Person.Surname);
            _adoNetDbHelper.command.Parameters.AddWithValue("@birthDate", model.Person.BirthDate.Date);
            _adoNetDbHelper.command.Parameters.AddWithValue("@placeOfBirth", model.Person.PlaceOfBirth);
            _adoNetDbHelper.command.Parameters.AddWithValue("@gender", model.Person.Gender);
            _adoNetDbHelper.command.Parameters.AddWithValue("@jobState", model.Person.JobState);
            _adoNetDbHelper.command.Parameters.AddWithValue("@jobDescription", model.Person.JobDescription);
            _adoNetDbHelper.command.Parameters.AddWithValue("@reference", model.Person.Reference ?? "");
            _adoNetDbHelper.command.Parameters.AddWithValue("@salary", model.Person.Salary);
            _adoNetDbHelper.command.Parameters.AddWithValue("@mobilePhone", model.Person.MobilePhone);
            _adoNetDbHelper.command.Parameters.AddWithValue("@homePhone", model.Person.HomePhone);
            _adoNetDbHelper.command.Parameters.AddWithValue("@motherName", model.Person.MotherName);
            _adoNetDbHelper.command.Parameters.AddWithValue("@fatherName", model.Person.FatherName);
            _adoNetDbHelper.command.Parameters.AddWithValue("@isMarried", model.Person.isMarried);
            _adoNetDbHelper.command.Parameters.AddWithValue("@educationalStatusId", model.Person.EducationalStatus);
            _adoNetDbHelper.command.Parameters.AddWithValue("@socialSecurityId", model.Person.SocialSecurityId);
            _adoNetDbHelper.command.Parameters.AddWithValue("@familyId", model.Person.FamilyId);

            _adoNetDbHelper.OpenSafeConnection();

            int count = _adoNetDbHelper.command.ExecuteNonQuery();

            _adoNetDbHelper.CloseSafeConnection();

            _adoNetDbHelper.command.Dispose();

            return(count);
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int familyId = _familyManager.GetFamilyByFatherTCNo(txtFatherNo.Text).Id;

            Person person = new Person()
            {
                Id                = personId,
                TC                = txtTcNo.Text,
                Citizenship       = txtCitizenship.Text,
                Name              = txtName.Text,
                Surname           = txtSurname.Text,
                BirthDate         = dateBirthDate.Value,
                PlaceOfBirth      = txtPlaceOfBirth.Text,
                Gender            = chckMan.Checked,
                JobState          = chckWorking.Checked,
                Reference         = rchReference.Text,
                JobDescription    = txtJob.Text,
                Salary            = numSalary.Value,
                MobilePhone       = mskPhone.Text,
                HomePhone         = mskPhone.Text,
                MotherName        = txtMotherName.Text,
                FatherName        = txtFatherName.Text,
                isMarried         = cmbMarried.SelectedItem.ToString(),
                EducationalStatus = GetCurrentEducationalStatusId(),
                SocialSecurityId  = GetCurrentSocialSecurityId(),
                FamilyId          = familyId
            };

            FamilyUpdateModel model = new FamilyUpdateModel();

            model.Person     = person;
            model.LastTCNo   = personTCNo;
            model.FatherTCNo = txtFatherNo.Text;

            var layerResult = _personManager.Update(model);

            if (layerResult.HasError())
            {
                string firstError = layerResult.Errors.FirstOrDefault();
                MessageBox.Show(firstError, "", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            else
            {
                MessageBox.Show("Düzenleme işlemi başarılı, yönlendiriliyorsunuz..", "", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.DialogResult = DialogResult.Yes;
                this.Close();
                this.Dispose();
            }


            //if (FatherTC == personTC)
            //{
            //    helper.command = helper.connection.CreateCommand();

            //    int familyId = GetFamilyId(personTC);

            //    helper.command.CommandText = "UPDATE Family SET FatherNo=@p1 WHERE Id=@p2";

            //    helper.command.Parameters.AddWithValue("@p1", txtTcNo.Text);
            //    helper.command.Parameters.AddWithValue("@p2", familyId);

            //    helper.command.ExecuteReader();
            //}
        }
Exemplo n.º 3
0
        public LayerResult <Person> Update(FamilyUpdateModel model)
        {
            LayerResult <Person> layerResult = new LayerResult <Person>();

            layerResult.Result = model.Person;

            //this validation base will be refactoring!
            if (string.IsNullOrEmpty(model.Person.TC))
            {
                layerResult.AddError("T.C kimlik numarası boş geçilemez!");
            }
            if (model.Person.TC.Length != 11)
            {
                layerResult.AddError("T.C kimlik numarası 11 karakter olmalıdır!");
            }
            if (string.IsNullOrEmpty(model.Person.Citizenship))
            {
                layerResult.AddError("Uyruk boş geçilemez!");
            }
            if (string.IsNullOrEmpty(model.Person.Name))
            {
                layerResult.AddError("İsim alanı boş geçilemez!");
            }
            if (string.IsNullOrEmpty(model.Person.Surname))
            {
                layerResult.AddError("Soyisim alanı boş geçilemez!");
            }
            if (model.Person.BirthDate == null)
            {
                layerResult.AddError("Doğum Tarihi boş geçilemez!");
            }
            if (string.IsNullOrEmpty(model.Person.PlaceOfBirth))
            {
                layerResult.AddError("Doğum yeri boş geçilemez!");
            }
            if (string.IsNullOrEmpty(model.Person.MotherName))
            {
                layerResult.AddError("Anne adı boş geçilemez!");
            }
            if (string.IsNullOrEmpty(model.Person.FatherName))
            {
                layerResult.AddError("Baba adı numarası boş geçilemez!");
            }

            if (layerResult.HasError())
            {
                return(layerResult);
            }

            int count = _personDal.Update(model);

            if (count == 0)
            {
                layerResult.AddError("Güncelleme işlemi gerçekleştirilemedi!");
            }

            else
            {
                if (model.LastTCNo == model.FatherTCNo)
                {
                    var family = _familyManager.GetFamilyByFatherTCNo(model.FatherTCNo);

                    family.FatherNo = model.Person.TC;

                    _familyManager.Update(family);
                }
            }


            return(layerResult);
        }