public ServiceResult <int?> InsertPerson(PersonModel personModel) { var person = new Person(); Mapper.Map(personModel, person); // For demo purposes, let's assume we only accept colleagues. You could easily add Type to the PersonModel and let external code set it person.Type = PersonType.Colleague; List <ValidationResult> errors = person.Validate().ToList(); if (errors.Any()) { var result = new ServiceResult <int?> { Errors = Mapper.Map(errors, new List <ValidationResultModel>()) }; return(result); } using (_unitOfWorkFactory.Create()) { _peopleRepository.Add(person); } return(new ServiceResult <int?> { Data = person.Id }); }
public void RepositoryShouldAddPersonWithAddressAndDelete() { //Arrage _repository = new PeopleRepository(_dbContext); var person = Data.GetPeople().First <Person>(); //Execute var personCountBeforeAdd = _dbContext.People.ToList().Count; var addressCountBeforeAdd = _dbContext.Address.ToList().Count; _repository.Add(person); var addedPerson = _repository.GetById(personCountBeforeAdd + 1); //Assert Assert.AreEqual(person.FirstName, addedPerson.FirstName); Assert.AreEqual(person.LastName, addedPerson.LastName); Assert.AreEqual(_dbContext.People.ToList().Count, personCountBeforeAdd + 1); Assert.AreEqual(_dbContext.Address.ToList().Count, addressCountBeforeAdd + 1); //Clean Up _repository.Delete(personCountBeforeAdd + 1); Assert.AreEqual(_dbContext.People.ToList().Count, personCountBeforeAdd); Assert.AreEqual(_dbContext.Address.ToList().Count, addressCountBeforeAdd); }
public async Task <Unit> Handle(CreatePeopleCommand request, CancellationToken cancellationToken) { People people = new() { Name = request.Name, Phone = request.Phone, Surname = request.Surname, Dni = request.Dni }; await peopleRepository.Add(people); return(Unit.Value); }
public ActionResult Create([Bind("PersonId,Name,Birthday,Parent1Id,Parent2Id")] People people) { if (ModelState.IsValid) { repository.Add(people); return(RedirectToAction("Index")); } return(View(people)); }
public IActionResult Create([FromBody] PersonViewModel person) { var model = person.Adapt <Person>(); model.OwnerId = _activeUser.GetUserId(); _peopleRepository.Add(model); return(Created(nameof(GetById), new { id = model.Id })); }
public IActionResult Post([FromBody] Person person) { if (ModelState.IsValid) { _peopleRepository.Add(person); return(Ok()); } return(BadRequest()); }
public IHttpActionResult PostPerson(Person person) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _repository.Add(person); return(CreatedAtRoute("DefaultApi", new { id = person.PersonId }, person)); }
public async Task <IActionResult> Add([FromBody] PeopleViewModel people) { AddEntityResponse <People> newPeopleAdded = await _peopleRepository.Add(people); if (newPeopleAdded.EntitySuccessfullyAdded) { return(RedirectToAction(nameof(Get), new { newPeopleAdded.Entity.Id })); } return(Ok(new { status = "error", message = "add people failed" })); }
public void AddPerson(Person person) { using (IUnitOfWork uow = new NHibernateUnitOfWork()) { try { _repository.Add(person); uow.Commit(); } catch (Exception ex) { uow.RollBack(); } } }
// POST api/People public IHttpActionResult Post([FromBody] Person value) { try { _db.Add(value); } catch (Exception ex) { ModelState.AddModelError(nameof(Person), ex.Message); return(BadRequest(ModelState)); } return(Ok()); }
public string AddPerson(People people) { if (people.Id != 0) { return(UpdatePerson(people.Id, people)); } else { if (!_peopleRepository.GetEntireTable().Where(x => x.Name == people.Name).Any()) { _peopleRepository.Add(people); _peopleRepository.SaveChanges(); return(null); } return("Duplicate Name(" + people.Name + "). Please enter another name"); } }
private void btnAddItem_Click(object sender, RoutedEventArgs e) { Person person = getPersonFromInfoEditor(); if (person != null) { try { repo.Add(person); this.dataGridPeople.Items.Refresh(); (this.tabSystem.Items[1] as TabItem).Visibility = Visibility.Collapsed; } catch (ArgumentException ex) { MessageBox.Show(String.Format("Людина з таким ІД вже існує", ex.ParamName), this.Title); } } }
public Task <bool> Handle(RegisterNewPeopleCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(Task.FromResult(false)); } var people = new People() { Name = request.Name, Email = request.Email, Skype = request.Skype, Phone = request.Phone, LinkedIn = request.LinkedIn, City = request.City, State = request.State, Portfolio = request.Portfolio, IsDesigner = request.IsDesigner, IsDeveloper = request.IsDeveloper, Occupation = request.Occupation, Knowledge = request.Knowledge, EntityState = EntityStateOptions.Active, }; if (peopleRepository.GetByEmail(people.Email) != null) { bus.RaiseEvent(new DomainNotification(request.MessageType, "The people e-mail has already been taken.")); return(Task.FromResult(false)); } peopleRepository.Add(people); if (Commit()) { bus.RaiseEvent(new PeopleRegisteredEvent(people.Id, people.Name, people.Email, people.Skype, people.Phone, people.LinkedIn, people.IsDeveloper, people.IsDesigner)); } return(Task.FromResult(true)); }
public ActionResult Create(CreateAndEditPerson createAndEditPerson) { if (ModelState.IsValid) { try { using (_unitOfWorkFactory.Create()) { Person person = new Person(); Mapper.Map(createAndEditPerson, person); _peopleRepository.Add(person); return(RedirectToAction("Index")); } } catch (ModelValidationException mvex) { foreach (var error in mvex.ValidationErrors) { ModelState.AddModelError(error.MemberNames.FirstOrDefault() ?? "", error.ErrorMessage); } } } return(View()); }
public IActionResult Post([FromBody] People people) { _repository.Add(people); return(Ok()); }
public async Task CreatePerson(PersonModel model) { var person = Mapper.Map <Person>(model); await _peopleRepository.Add(person); }
public void AddPeople(People people) { peopleRepository.Add(people); }
public void AddPerson(People people) { _personRepository.Add(people); _personRepository.SaveChanges(); }
public void Post([FromBody] Person value) { _peopleRepository.Add(value); }
public void CannotAddSameIDs() { repo.Add(new Person { ID = 1 }); }
public void CreatePerson(Person person) { _peopleRepository.Add(person); _unitOfWork.Commit(); }
public bool Save(PeopleVM people) { var result = _repository.Add(_mapper.Map <People>(people)); return(result > 0); }