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
            });
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 public ActionResult Create([Bind("PersonId,Name,Birthday,Parent1Id,Parent2Id")] People people)
 {
     if (ModelState.IsValid)
     {
         repository.Add(people);
         return(RedirectToAction("Index"));
     }
     return(View(people));
 }
コード例 #5
0
        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 }));
        }
コード例 #6
0
ファイル: PeopleController.cs プロジェクト: kurachevskyi/Task
        public IActionResult Post([FromBody] Person person)
        {
            if (ModelState.IsValid)
            {
                _peopleRepository.Add(person);
                return(Ok());
            }

            return(BadRequest());
        }
コード例 #7
0
        public IHttpActionResult PostPerson(Person person)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repository.Add(person);

            return(CreatedAtRoute("DefaultApi", new { id = person.PersonId }, person));
        }
コード例 #8
0
        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" }));
        }
コード例 #9
0
 public void AddPerson(Person person)
 {
     using (IUnitOfWork uow = new NHibernateUnitOfWork())
     {
         try
         {
             _repository.Add(person);
             uow.Commit();
         }
         catch (Exception ex)
         {
             uow.RollBack();
         }
     }
 }
コード例 #10
0
        // 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());
        }
コード例 #11
0
 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");
     }
 }
コード例 #12
0
        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);
                }
            }
        }
コード例 #13
0
        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));
        }
コード例 #14
0
 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());
 }
コード例 #15
0
 public IActionResult Post([FromBody] People people)
 {
     _repository.Add(people);
     return(Ok());
 }
コード例 #16
0
 public async Task CreatePerson(PersonModel model)
 {
     var person = Mapper.Map <Person>(model);
     await _peopleRepository.Add(person);
 }
コード例 #17
0
 public void AddPeople(People people)
 {
     peopleRepository.Add(people);
 }
コード例 #18
0
 public void AddPerson(People people)
 {
     _personRepository.Add(people);
     _personRepository.SaveChanges();
 }
コード例 #19
0
 public void Post([FromBody] Person value)
 {
     _peopleRepository.Add(value);
 }
コード例 #20
0
 public void CannotAddSameIDs()
 {
     repo.Add(new Person {
         ID = 1
     });
 }
コード例 #21
0
 public void CreatePerson(Person person)
 {
     _peopleRepository.Add(person);
     _unitOfWork.Commit();
 }
コード例 #22
0
        public bool Save(PeopleVM people)
        {
            var result = _repository.Add(_mapper.Map <People>(people));

            return(result > 0);
        }