public async Task AddPerson(BasePersonDTO NewPersonToAdd)
        {
            Person newPerson = (Person)NewPersonToAdd;

            context.People.Add(newPerson);
            await saveChanges();
        }
        public void FromDTOToPerson()
        {
            var dto = new BasePersonDTO();

            var person = (Person)dto;

            Assert.IsType <Person>(person);
        }
        public void FromDTOToClientPerson()
        {
            var dto = new BasePersonDTO();

            var clientPerson = (ClientBasePerson)dto;

            Assert.IsType <ClientBasePerson>(clientPerson);
        }
Exemple #4
0
        public async Task <ActionResult <BasePersonDTO> > Put(string id, [FromBody] BasePersonDTO value)
        {
            var check = await context.GetPersonById(id);

            if (check == null)
            {
                return(NotFound());
            }

            await context.UpdatePerson(value);

            var result = await context.GetPersonById(id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok((BasePersonDTO)result));
        }
Exemple #5
0
        public async Task <ActionResult <BasePersonDTO> > Post([FromBody] BasePersonDTO value)
        {
            var check = await context.GetPersonById(value.Id);

            if (check != null)
            {
                return(Conflict());
            }

            await context.AddPerson(value);

            var result = await context.GetPersonById(value.Id);

            if (result == null)
            {
                return(NotFound());
            }

            return(Ok((BasePersonDTO)result));
        }
Exemple #6
0
        public async Task <ActionResult <BasePersonDTO> > GetInvitedPeopleByActivityId(int id)
        {
            var result = await activityContext.GetInvitesdByActivityId(id);

            if (result == null)
            {
                return(NotFound());
            }

            try
            {
                BasePersonDTO castResult = (BasePersonDTO)result;

                return(Ok(castResult));
            }
            catch (InvalidCastException ex)
            {
                return(NotFound(ex));
            }
        }
        public async Task UpdatePerson(BasePersonDTO updatedPersonData)
        {
            var PersonFromDb = await GetPersonById(updatedPersonData.Id);

            if (PersonFromDb.FirstName != updatedPersonData.FirstName)
            {
                PersonFromDb.FirstName = updatedPersonData.FirstName;
            }

            if (PersonFromDb.MiddleName != updatedPersonData.MiddleName)
            {
                PersonFromDb.MiddleName = updatedPersonData.MiddleName;
            }

            if (PersonFromDb.LastName != updatedPersonData.LastName)
            {
                PersonFromDb.LastName = updatedPersonData.LastName;
            }

            context.People.Update(PersonFromDb);

            await saveChanges();
        }