public async Task <ActionResult <ParticipationViewModel> > GetParticipationAsync(Guid personId, Guid projectId)
        {
            if (personId == Guid.Empty || projectId == Guid.Empty)
            {
                return(BadRequest("No valid id."));
            }
            try
            {
                TaskResult <Participation>
                result = await participationService.GetParticipationAsync(personId, projectId);

                if (!result.Succeeded)
                {
                    if (result.Data == null)
                    {
                        return(NoContent());
                    }
                }
                ParticipationViewModel participationViewModel = ParticipationViewModel.CreateVm(result.Data);

                return(Ok(participationViewModel));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(GetParticipationAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
        public async Task <ActionResult <ParticipationViewModel> > SaveParticipationAsync(
            [FromBody] ParticipationViewModel participationViewModel)
        {
            if (participationViewModel?.Person == null || participationViewModel.Project == null)
            {
                return(BadRequest("No valid participation received"));
            }
            TaskResult <Participation> result = null;

            try
            {
                Participation participation = (await participationService.GetParticipationAsync(
                                                   participationViewModel.Person.Id,
                                                   participationViewModel.Project.Id)).Data;
                if (participation != null)
                {
                    participation.Active     = true;
                    participation.LastEditBy = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity);
                    result = await participationService.UpdateParticipationAsync(participation);
                }

                else
                {
                    participation            = ParticipationViewModel.CreateParticipation(participationViewModel);
                    participation.Active     = true;
                    participation.LastEditBy = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity);
                    if (participation.Id == Guid.Empty)
                    {
                        //create participation
                        result = await participationService.AddParticipationAsync(participation);
                    }
                }

                if (result == null || !result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel
                    {
                        Type = Type.Error, Message = result?.Message
                    }));
                }
                return(Ok(ParticipationViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(SaveParticipationAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }
        public async Task <ActionResult <ParticipationViewModel> > UpdateParticipationAsync(
            [FromBody] ParticipationViewModel participationViewModel)
        {
            if (participationViewModel?.Person == null ||
                participationViewModel.Person.Id == Guid.Empty ||
                participationViewModel.Project == null ||
                participationViewModel.Project.Id == Guid.Empty)
            {
                return(BadRequest("No valid participation received"));
            }

            TaskResult <Participation> result = new TaskResult <Participation>();

            try
            {
                Participation oldParticipation = (await participationService
                                                  .GetParticipationAsync(participationViewModel.Person.Id, participationViewModel.Project.Id)
                                                  ).Data;
                if (!oldParticipation.RowVersion.SequenceEqual(participationViewModel.RowVersion))
                {
                    return(BadRequest("Outdated entity received"));
                }

                Participation updatedParticipation = ParticipationViewModel.CreateParticipation(participationViewModel);

                if (oldParticipation.ProjectId != updatedParticipation.ProjectId)
                {
                    result.Message = "A participation cannot change project";
                    return(BadRequest(result));
                }

                if (oldParticipation.PersonId != updatedParticipation.PersonId)
                {
                    result.Message = "A participation cannot change user";
                    return(BadRequest(result));
                }

                oldParticipation.Availabilities         = updatedParticipation.Availabilities;
                oldParticipation.MaxWorkingHoursPerWeek = updatedParticipation.MaxWorkingHoursPerWeek;
                oldParticipation.Active     = updatedParticipation.Active;
                oldParticipation.Remark     = updatedParticipation.Remark;
                oldParticipation.Person     = null;
                oldParticipation.Project    = null;
                oldParticipation.LastEditBy = IdentityHelper.GetOid(HttpContext.User.Identity as ClaimsIdentity);

                result = await participationService.UpdateParticipationAsync(oldParticipation);

                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }

                result.Data.Person  = updatedParticipation.Person;
                result.Data.Project = updatedParticipation.Project;
                return(Ok(ParticipationViewModel.CreateVm(result.Data)));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(UpdateParticipationAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }