Пример #1
0
            private void UpdateList(PropertyChangedMessage <Person> obj)
            {
                var person         = obj.NewValue;
                var observedPerson = People.FirstOrDefault(i => i.Id == person.Id);

                //add person if new to persist
                if (observedPerson == null && !person.IsEmpty)
                {
                    People.Add(person);
                    _peopleService.AddPerson(person);
                }
                //if found and delete flag set
                if (person.Delete)
                {
                    People.Remove(person);
                    _peopleService.RemovePerson(person);
                }
                //if found, do an update
                else if (observedPerson != null)
                {
                    observedPerson.FirstName = person.FirstName;
                    observedPerson.LastName  = person.LastName;
                    observedPerson.Birthday  = person.Birthday;
                    observedPerson.Email     = person.Email;
                    observedPerson.Delete    = person.Delete;

                    _peopleService.UpdatePerson(person);
                }
            }
Пример #2
0
        public void TestAddPerson()
        {
            var person = new Person {
                Id = 5, Name = "Person Name"
            };
            var personResponse = service.AddPerson(person);

            personResponse.Data.Should().Be(person);
        }
        public void AddPerson_Should_Insert_Person_Into_Database()
        {
            Person person = new Person {
                Name = "personName"
            };

            _peopleService.AddPerson(person);

            IEnumerable <Person> personsOnDb = _personRepository.RetrieveAll();

            personsOnDb.Should().HaveCount(1);
            personsOnDb.First().Name.Should().Be(person.Name);
        }
        public IActionResult AddPerson(PersonDto personDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var personBl = _mapper.Map <PersonBl>(personDto);

            personBl = _people.AddPerson(personBl);

            return(Created(new Uri(Request.GetDisplayUrl() + personBl.PersonId),
                           _mapper.Map <PersonDto>(personBl)));
        }
Пример #5
0
        public JsonResult AddPerson([FromBody] PersonModel person)
        {
            if (person == null)
            {
                return(new JsonResult("Person is blank"));
            }

            var result = _peopleservice.AddPerson(person);

            if (!result)
            {
                return(new JsonResult("Person could not be added"));
            }
            return(new JsonResult("Person Added"));
        }
Пример #6
0
 public IActionResult Create(Person person)
 {
     if (ModelState.IsValid)
     {
         try
         {
             _peopleService.AddPerson(person);
         }
         catch (Exception)
         {
             throw;
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(person));
 }
Пример #7
0
        public async Task <IActionResult> PostAsync([FromBody] PersonDto personDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                await _peopleService.AddPerson(personDto);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(NoContent());
        }
Пример #8
0
        public IActionResult PostPerson([FromBody] Person person)
        {
            _service.AddPerson(person);

            return(CreatedAtAction("GetPerson", new { id = person.PersonId }, person));
        }
Пример #9
0
 public void Post([FromBody] PersonModel person)
 {
     _peopleService.AddPerson(ModelConverter.GetPerson(person));
 }
Пример #10
0
        public async Task <GenericResult <StudentInformationDto> > AddNewStudent(NewStudentInformationDto newStudentInformationDto)
        {
            if (string.IsNullOrEmpty(newStudentInformationDto.StudentNumber))
            {
                return(GenericResult <StudentInformationDto> .UserSafeError($"Error! Student number can not be null"));
            }
            using (var transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                try
                {
                    if (await _studentRepo.AsQueryable().AnyAsync(x => x.StudentNumber == newStudentInformationDto.StudentNumber))
                    {
                        transaction.Dispose();
                        return(GenericResult <StudentInformationDto> .UserSafeError($"Error! Student number: \"{newStudentInformationDto.StudentNumber}\" is already in use"));
                    }
                    newStudentInformationDto.RegistrationDate = DateTime.Now;
                    var newPopulationResult = await _populationService.AddPopulationInfo(newStudentInformationDto.NewUserDto.PersonDto.PopulationInformationDto);

                    if (newPopulationResult.IsSucceed)
                    {
                        newStudentInformationDto.NewUserDto.PersonDto.FKPopulationInformationID = newPopulationResult.Data;
                        var newPersonResult = await _peopleService.AddPerson(newStudentInformationDto.NewUserDto.PersonDto);

                        if (newPersonResult.IsSucceed)
                        {
                            newStudentInformationDto.NewUserDto.FKPersonID = newPersonResult.Data.ID;
                            var newUserResult = await _userService.AddNewUser(newStudentInformationDto.NewUserDto);

                            if (newUserResult.IsSucceed)
                            {
                                newStudentInformationDto.FKUserID = newUserResult.Data.ID;
                                var newStudentDbEntity = _mapper.Map <StudentInformation>(newStudentInformationDto);

                                var newStudent = await _studentRepo.InsertAsync(newStudentDbEntity);

                                await _eventPublisher.PublishAsync(new NewStudentCreatedEvent()
                                {
                                    FKUserID      = newStudent.FKUserID,
                                    StudentNumber = newStudent.StudentNumber
                                });

                                transaction.Complete();
                                return(GenericResult <StudentInformationDto> .Success(_mapper.Map <StudentInformationDto>(newStudent)));
                            }
                            else
                            {
                                transaction.Dispose();
                                return(newUserResult.ConvertTo(default(StudentInformationDto), "An error occurred while adding new user."));
                            }
                        }
                        else
                        {
                            await _populationService.Delete(newPopulationResult.Data);

                            transaction.Dispose();
                            return(newPersonResult.ConvertTo(default(StudentInformationDto), "An error occurred while adding new person."));
                        }
                    }
                    else
                    {
                        transaction.Dispose();
                        return(newPopulationResult.ConvertTo(default(StudentInformationDto), "An error occurred while adding new population."));
                    }
                }
                catch (Exception e)
                {
                    transaction.Dispose();
                    return(GenericResult <StudentInformationDto> .Error(e));
                }
            }
        }