Esempio n. 1
0
        public async Task <ActionResult <List <ManagerViewModel> > > GetProjectManagersAsync(Guid projectId)
        {
            if (projectId == Guid.Empty)
            {
                return(BadRequest("No valid id received"));
            }
            try
            {
                TaskListResult <Manager> result = await personService.GetManagersAsync(projectId);

                //get users from b2c and add tot DTO
                foreach (Manager manager in result.Data)
                {
                    User temp = (await personService.GetUserAsync(manager.PersonId)).Data;
                    if (temp == null)
                    {
                        continue;
                    }
                    PersonViewModel vm =
                        PersonViewModel.CreateVmFromUser(temp, Extensions.GetInstance(b2CExtentionApplicationId));
                    if (vm == null)
                    {
                        continue;
                    }

                    Person person = PersonViewModel.CreatePerson(vm);
                    manager.Person = person;
                }

                if (!result.Succeeded)
                {
                    return(UnprocessableEntity(new ErrorViewModel {
                        Type = Type.Error, Message = result.Message
                    }));
                }
                if (result.Data == null || result.Data.Count == 0)
                {
                    return(Ok(new List <ManagerViewModel>()));
                }
                List <ManagerViewModel> managerVmList = result.Data.Select(ManagerViewModel.CreateVm).ToList();
                return(Ok(managerVmList));
            }
            catch (Exception ex)
            {
                string message = GetType().Name + "Error in " + nameof(GetProjectManagersAsync);
                logger.LogError(ex, message);
                return(UnprocessableEntity(new ErrorViewModel {
                    Type = Type.Error, Message = message
                }));
            }
        }