private async void btnEdit_Click(object sender, EventArgs e) { if (comboCategory.SelectedValue != null) { var categories = (Category)comboCategory.SelectedItem; categories.CategoryName = txtName.Text; categories.Image = WindowsFormsUtilities.WindowsImageConverter.ConvertImage(pictureBox1.Image); var validation = WindowsFormValidationContext.Validated <Category>(categories); if (validation.Item1) { categoriesRepository.Edit(categories); var result = await categoriesRepository.SaveChangesAsync(); if (result > 0) { MessageBox.Show("The Category has been Edit", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { foreach (var item in validation.Item2) { MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void CreateRoom() { var room = new Room() { CategoryID = Convert.ToInt32(comboCategory.SelectedValue), Image = WindowsImageConverter.ConvertImage(pictureBox1.Image), IsDeleted = false, Price = txtPrice.Value, Number = Convert.ToInt32(txtRoomNumber.Value), IsEmpty = checkIsAvaiable.Checked, IsAvailable = checkIsEmpty.Checked, NumberOfBeds = Convert.ToInt32(txtNumberOfBeds.Value), NumberOfPeople = Convert.ToInt32(txtPeopleCapacity.Value), }; var result = WindowsFormValidationContext.Validated <Room>(room); if (result.Item1) { roomReposity.Add(room); if (roomReposity.SaveChanges() > 0) { MessageBox.Show("The Room has been saved", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { foreach (var item in result.Item2) { MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private async void btnCreate_Click(object sender, EventArgs e) { var categories = new Category() { CategoryName = txtName.Text, Image = WindowsFormsUtilities.WindowsImageConverter.ConvertImage(pictureBox1.Image) }; var validation = WindowsFormValidationContext.Validated <Category>(categories); if (validation.Item1) { categoriesRepository.Add(categories); var result = await categoriesRepository.SaveChangesAsync(); if (result > 0) { MessageBox.Show("The Category has been Added", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { foreach (var item in validation.Item2) { MessageBox.Show(item.ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void Validator_WhenUserDoesnNotFillAll_ListIsGreaterThanZero() { var result = WindowsFormValidationContext.Validated <EmployeesMoq>(new EmployeesMoq() { Name = "Mohamed", Salary = null }); Assert.Greater(result.Item2.Count, 0); }
public void Validator_WhenUserDoesnNotFillAll_NotNull() { var result = WindowsFormValidationContext.Validated <EmployeesMoq>(new EmployeesMoq() { Name = "Mohamed", Salary = null }); Assert.IsNotNull(result.Item2); }
public void Validator_WhenUserFillAll_true() { var result = WindowsFormValidationContext.Validated <EmployeesMoq>(new EmployeesMoq() { Name = "Mohamed", Salary = 1000 }); Assert.True(result.Item1); }