public async Task <IActionResult> Put([FromBody] EventDto eventToModify, [FromRoute] long id)
        {
            if (eventToModify == null)
            {
                return(BadRequest());
            }
            if (id != eventToModify.Id)
            {
                return(BadRequest());
            }
            User userOfChange = await userService.FindByNameAsync(User.Identity.Name);

            Event oldOne = await eventService.GetEventByIdWithAllIncludesAsync(id);

            List <Contact>      contactsParticipated = new List <Contact>();
            List <Organization> orgasParticipated    = new List <Organization>();

            foreach (ParticipatedDto part in eventToModify.Participated)
            {
                if (part.ModelType == MODEL_TYPE.CONTACT)
                {
                    Contact cont = await contactService.GetByIdAsync(part.ObjectId);

                    if (cont != null)
                    {
                        contactsParticipated.Add(cont);
                    }
                }
                else if (part.ModelType == MODEL_TYPE.ORGANIZATION)
                {
                    Organization orga = await orgaService.GetByIdAsync(part.ObjectId);

                    if (orga != null)
                    {
                        orgasParticipated.Add(orga);
                    }
                }
            }
            await modService.UpdateEventsAsync(userOfChange, oldOne, eventToModify, contactsParticipated, orgasParticipated);

            if (await eventService.ModifyEventAsync(eventToModify))
            {
                await modService.CommitChanges();
            }
            return(Ok(eventToModify));
        }
Exemple #2
0
        public async Task <IActionResult> Put([FromRoute] long id, [FromBody] ContactDto contact)
        {
            if (contact == null)
            {
                return(Conflict());
            }
            User userOfModification = await userService.FindByNameAsync(User.Identity.Name);

            var mappedContact = _mapper.Map <Contact>(contact);
            await modService.UpdateContactAsync(userOfModification, await contactService.GetByIdAsync(id), mappedContact, await userService.IsDataSecurityEngineer(userOfModification.Id));

            if (await contactService.UpdateAsync(mappedContact, id))
            {
                await modService.CommitChanges();

                return(Ok(contact));
            }
            else
            {
                return(Conflict());
            }
        }
Exemple #3
0
        public async Task <IActionResult> Put([FromBody] OrganizationDto organization, [FromRoute] long id)
        {
            if (organization == null)
            {
                return(BadRequest());
            }
            if (id != organization.Id)
            {
                return(BadRequest());
            }
            User userOfChange = await userService.FindByNameAsync(User.Identity.Name);

            var mappedOrganization = _mapper.Map <Organization>(organization);
            await modService.UpdateOrganizationAsync(userOfChange, await _organizationService.GetByIdAsync(id), mappedOrganization, await userService.IsDataSecurityEngineer(userOfChange.Id));

            if (await _organizationService.UpdateAsyncWithAlleDependencies(mappedOrganization))
            {
                await modService.CommitChanges();
            }
            var organizationDto = _mapper.Map <OrganizationDto>(mappedOrganization);

            return(Ok(organizationDto));
        }