public void addPersonTest() { var person1 = new Person() { id = "klddhjfs", firstname = "lşs", lastname = "lşkf" }; var person2 = new Person() { id = "kdfhgvslds", firstname = "lşs", lastname = "lşkf" }; var options = new DbContextOptionsBuilder <DatabaseContext>() .UseInMemoryDatabase("person_db") .Options; using (var context = new DatabaseContext(options)) { var repository = new PersonService(context); repository.AddPerson(person1); repository.AddPerson(person2); context.SaveChanges(); } using (var context = new DatabaseContext(options)) { var repository = new PersonService(context); repository.GetPerson().Count.Equals(2); } }
static void SignUp() { Console.Clear(); Console.WriteLine(" Sign Up"); Console.WriteLine(" --------------------------"); Console.Write(" Please enter your first name: "); string firstNameSignUp = Console.ReadLine(); Console.Write(" Please enter your last name: "); string lastNameSignUp = Console.ReadLine(); Console.Write("Enter your age: "); int age = int.Parse(Console.ReadLine()); if (_personService.Exists(firstNameSignUp, lastNameSignUp, age)) { Console.WriteLine("This person already have an account. Please use 1 to log in"); } else { if (SignUpValidation(firstNameSignUp, lastNameSignUp, age)) { firstName = firstNameSignUp; lastName = lastNameSignUp; _personService.AddPerson(firstNameSignUp, lastNameSignUp, age); Console.WriteLine("New person added. Now you can use our library."); } } }
public PersonResource AddPerson(PersonDTO dto) { Person toAdd = new Person().CopyPropertiesFrom(dto); Person dbPerson = service.AddPerson(toAdd); PersonResource p = new PersonResource().CopyPropertiesFrom(dbPerson); p.NrBookings = dbPerson.Bookings.Count(); return(p); }
public void ThrowArgumentNullException_WhenPassedPersonIsNull() { // Arrange var personRepositoryMock = new Mock <IRepository <Person> >(); var personService = new PersonService(personRepositoryMock.Object); // Act && Assert Assert.Throws <ArgumentNullException>(() => personService.AddPerson(null)); }
// POST api/<controller> public void Post() { p.AddPerson(); //var person = new Repository<Person>(); //person.Add(new Person() { // Fname = "Sonny", // Mname = "Ramirez", // Lname = "Recio" //}); }
private void CreatePersons(int number, string lastName, int startAge, int ageStep = 5) { for (int i = 0; i < number; i++) { int N = i + 1; int age = startAge + i * ageStep; service.AddPerson(new Person() { FirstName = "Test " + N, LastName = lastName, Age = age }); } }
public ActionResult AddPerson(Person model) { var personAddResult = _personService.AddPerson(model); if (personAddResult) { return(Json(new { success = true, msg = $"Successfully added {model.FirstName}" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, msg = "Error while adding person" }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Post(Person person) { try { _personService.AddPerson(person); return(Ok()); } catch (Exception ex) { return(NotFound(ex)); } }
private void OnAddCommand(object obj) { var newPerson = new Person { FirstName = AddPerson.FirstName, LastName = AddPerson.LastName, ModifiedDate = DateTime.Now, }; string json = JsonConvert.SerializeObject(newPerson); personService.AddPerson(json); OnRequestClose(); }
public async Task New_person_is_saved() { var person = new Person() { TaxCode = "taxcode3", Firstname = "firstname3", Surname = "surname3" }; await PersonService.AddPerson(person); MockSet.Verify(m => m.Add(person), Times.Once); MockContext.Object.Persons.Count().ShouldBeEquivalentTo(3); MockContext.Verify(m => m.SaveChangesAsync(), Times.Once); }
public void ThrowInvalidOperationException_WhenPassedPersonExists() { // Arrange var personMock = new Mock <Person>(); var personRepositoryMock = new Mock <IRepository <Person> >(); var personService = new PersonService(personRepositoryMock.Object); ICollection <Person> filteredPeople = new List <Person>(); filteredPeople.Add(personMock.Object); personRepositoryMock.Setup(pr => pr.GetAllFiltered(It.IsAny <Expression <Func <Person, bool> > >())) .Returns(filteredPeople); // Act && Assert Assert.Throws <InvalidOperationException>(() => personService.AddPerson(personMock.Object)); }
public void CallAddMethodOfRepositoryOnce_WhenPassedPersonDoesNotExists() { // Arrange var personMock = new Mock <Person>(); var personRepositoryMock = new Mock <IRepository <Person> >(); var personService = new PersonService(personRepositoryMock.Object); IEnumerable <Person> filteredPeople = new List <Person>(); personRepositoryMock.Setup(pr => pr.GetAllFiltered(It.IsAny <Expression <Func <Person, bool> > >())) .Returns(filteredPeople); // Act personService.AddPerson(personMock.Object); // Assert personRepositoryMock.Verify(pr => pr.Add(personMock.Object), Times.Once); }
private void savePersonButton_Click(object sender, RoutedEventArgs e) { try { var selectedCompany = companyCombobox.SelectedItem as Company; _personService.AddPerson(new Person { FullName = nameTextBox.Text, CompanyId = selectedCompany?.Id }); nameTextBox.Text = null; setPeopleAmountLabel(); } catch (ArgumentException ex) { nameTextBox.Focus(); nameTextBox.SelectAll(); MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public async Task <IHttpActionResult> AddPerson() { try { var model = HttpContext.Current.Request.Form["NewUser"]; var user = JsonConvert.DeserializeObject <NewUser>(model); if (user == null) { return(BadRequest("no user data defined")); } var files = HttpContext.Current.Request.Files; await _personService.AddPerson(files, user); return(Ok()); } catch (Exception ex) { return(InternalServerError(ex)); } }
/// <summary> /// Execute method that is called when the submit action for the form is invoked. /// </summary> /// <param name="data"></param> /// <param name="formSubmitContext"></param> /// <returns></returns> protected override bool Execute(string data, FormSubmitContext formSubmitContext) { Assert.ArgumentNotNull(formSubmitContext, nameof(formSubmitContext)); if (!formSubmitContext.HasErrors) { Logger.Info(Invariant($"Form {formSubmitContext.FormId} submitted successfully."), this); //TODO: hard coded the form values. In order to make this dynamic, it needs to be tied to the form and it's form fields //This may be possible by looping over formSubmitContext.Fields string firstName = GetValue("FirstName", formSubmitContext); string lastName = GetValue("LastName", formSubmitContext); string email = GetValue("Email", formSubmitContext); string phone = GetValue("Phone", formSubmitContext); string address = GetValue("Address", formSubmitContext); string city = GetValue("City", formSubmitContext); string state = GetValue("State", formSubmitContext); //string state = GetValue("StateDD", formSubmitContext); string zip = GetValue("Zip", formSubmitContext); //TODO: hook this up with constructor injection IPersonService ps = new PersonService(); ID personID = ps.AddPerson(firstName, lastName, email, phone, address, city, state, zip); if (!ID.IsNullOrEmpty(personID)) { return(true); } else { return(false); } } return(false); }
public IActionResult AddPerson([FromBody] PersonCreateVm model) { var apiResult = Try(() => { return(_personService.AddPerson(model)); }); return(Ok(apiResult)); }
public void AddPersonTest() { var serv = new PersonService(new MVCHContext()); serv.AddPerson(new Person { FirstName = "Cedrick", LastName = "Sederiosa", MiddleInitial = "S.", Address = "3212 Kahel St., Sto. Domingo II, Pampanga", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("09/02/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+639495940509", Zip = "8000" }); serv.AddPerson(new Person { FirstName = "John", LastName = "Branzuela", MiddleInitial = "C.", Address = "Sasa Dose", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("10/04/1999", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000" }); serv.AddPerson(new Person { FirstName = "Nathan", LastName = "Naanep", MiddleInitial = "G.", Address = "Ilonggo", City = "Koronadal City", State = "Philippines", BirthDate = DateTime.ParseExact("03/25/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000" }); serv.AddPerson(new Person { FirstName = "Mecca", LastName = "Umapas", MiddleInitial = "S.", Address = "Surigao", City = "Surigao", State = "Philippines", BirthDate = DateTime.ParseExact("10/30/1999", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000" }); serv.AddPerson(new Person { FirstName = "Yoshi", LastName = "Aizawa", MiddleInitial = "M.", Address = "Mintal", City = "Davao City", State = "Japan", BirthDate = DateTime.ParseExact("12/13/1999", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000" }); serv.AddPerson(new Person { FirstName = "Adrian", LastName = "De Guzman", MiddleInitial = "A.", Address = "Ilonggo", City = "Tacurong City", State = "Philippines", BirthDate = DateTime.ParseExact("06/08/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000", PersonId = null }); serv.AddPerson(new Person { FirstName = "Abigail", LastName = "M.", MiddleInitial = "M.", Address = "3212 Kahel St., Sto. Domingo II, Pampanga", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("09/02/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000", PersonId = null }); serv.AddPerson(new Person { FirstName = "Anna", LastName = "O.", MiddleInitial = "O.", Address = "3212 Kahel St., Sto. Domingo II, Pampanga", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("09/02/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000", PersonId = null }); serv.AddPerson(new Person { FirstName = "Katriana", LastName = "B.", MiddleInitial = "B.", Address = "3212 Kahel St., Sto. Domingo II, Pampanga", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("09/02/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000", PersonId = null }); serv.AddPerson(new Person { FirstName = "Dexie", LastName = "Badilles", MiddleInitial = ".", Address = "Sasa", City = "Davao City", State = "Philippines", BirthDate = DateTime.ParseExact("09/02/2000", "mm/dd/yyyy", new CultureInfo("en-PH")), Email = "*****@*****.**", PhoneNumber = "+63969696969", Zip = "8000", PersonId = null }); }
private void btnCommit_Click(object sender, EventArgs e) //提交添加或者修改 { //判断输入 if (string.IsNullOrWhiteSpace(txtName.Text)) { MessageBox.Show("姓名不允许为空!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); return; } if (CheckInput.IsChinese(txtName.Text)) { MessageBox.Show("姓名必须为中文!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); txtName.Focus(); return; } if (string.IsNullOrWhiteSpace(txtMobile.Text)) { MessageBox.Show("号码不允许为空!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); txtMobile.Focus(); return; } if (CheckInput.IsMobile(txtMobile.Text.Trim())) { MessageBox.Show("号码必须为11位数字!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); txtMobile.Focus(); return; } Person objPerson = new Person() { PersonID = Convert.ToInt32(txtNum.Text.Trim()), PersonName = txtName.Text, PersonMobile = txtMobile.Text.Trim(), }; switch (actionFlag) { case 1: objPersonService.AddPerson(objPerson, Program.objListPerson); dgvPerson.DataSource = null; dgvPerson.DataSource = Program.objListPerson; txtNum.Text = dgvPerson.Rows[dgvPerson.Rows.Count - 1].Cells[0].Value.ToString(); txtNum.Text = dgvPerson.Rows[dgvPerson.Rows.Count - 1].Cells[1].Value.ToString(); txtNum.Text = dgvPerson.Rows[dgvPerson.Rows.Count - 1].Cells[2].Value.ToString(); lbTotal.Text = (int.Parse(lbTotal.Text) + 1).ToString(); EnableButton(); MessageBox.Show("添加成功!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); break; case 2: objPersonService.UpdatePerson(objPerson, Program.objListPerson); dgvPerson.DataSource = null; dgvPerson.DataSource = Program.objListPerson; EnableButton(); MessageBox.Show("修改成功!", "系统消息:", MessageBoxButtons.OK, MessageBoxIcon.Information); break; default: break; } }
public ActionResult Create(Person person) { personService.AddPerson(person); return(RedirectToAction("Index")); }