Example #1
0
        private EmployeeFavInfoModel EmployeeToEmployeeFavModel(Employee employee)
        {
            List <EmployeeFavServiceModel> serviceModels = new List <EmployeeFavServiceModel>();

            if (employee.EmployeeServices != null && employee.EmployeeServices.Count > 0)
            {
                employee.EmployeeServices.ForEach(serviceEp => {
                    var serviceModel = new EmployeeFavServiceModel
                    {
                        ServiceId   = serviceEp.ServiceId.ToString(),
                        ServiceName = serviceEp.Service.Name
                    };
                    serviceModels.Add(serviceModel);
                });
            }

            var companyModel = new CompanyFavInfoModel
            {
                CompanyId = employee.CompanyId.ToString(),
                Name      = employee.Company?.User?.Name ?? String.Empty,
                Image     = employee.Company?.User?.Image ?? String.Empty,
                Email     = employee.Company?.User?.Email ?? String.Empty,
                Descricao = employee?.Company?.Descricao ?? String.Empty,
                Link      = _companyRepository.GetCompanyLink(employee.CompanyId)
            };

            EmployeeFavInfoModel employeeModel = new EmployeeFavInfoModel
            {
                EmployeeId = employee.EmployeeId.ToString(),
                Link       = GetEmployeeLink(employee.EmployeeId),
                Name       = employee.User.Name,
                Email      = employee.User.Email,
                Descricao  = employee.Descricao,
                Image      = employee.User.Image,
                Services   = serviceModels,
                Company    = companyModel
            };

            return(employeeModel);
        }
Example #2
0
        public ResponseModel GetClientFavoriteEmployees(string userId)
        {
            ResponseModel response = new ResponseModel();

            try
            {
                if (GuidUtil.IsGuidValid(userId))
                {
                    var client = _clientRepository.GetClientByUserId(Guid.Parse(userId));
                    if (client != null)
                    {
                        List <EmployeeFavInfoModel> employeesModel = new List <EmployeeFavInfoModel>();

                        var employees = _employeeRepository.GetEmployeesByClientId(client.ClientId);
                        if (employees != null && employees.Count > 0)
                        {
                            employees.ForEach(employee =>
                            {
                                List <EmployeeFavServiceModel> serviceModels = new List <EmployeeFavServiceModel>();
                                var employeeServices = employee.EmployeeServices?.Select(x => x.Service).ToList();
                                if (employeeServices != null && employeeServices.Count > 0)
                                {
                                    employeeServices.ForEach(service => {
                                        var serviceModel = new EmployeeFavServiceModel {
                                            ServiceId   = service.ServiceId.ToString(),
                                            ServiceName = service.Name
                                        };

                                        serviceModels.Add(serviceModel);
                                    });
                                }

                                var companyModel = new CompanyFavInfoModel {
                                    CompanyId = employee.Company?.CompanyId.ToString(),
                                    Name      = employee.Company?.User?.Name,
                                    Email     = employee.Company?.User?.Email,
                                    Image     = employee.Company?.User?.Image,
                                    Descricao = employee?.Company?.Descricao,
                                    Link      = _companyService.GetCompanyLink(employee.CompanyId)
                                };

                                var employeeModel = new EmployeeFavInfoModel
                                {
                                    EmployeeId = employee.EmployeeId.ToString(),
                                    Link       = _employeeService.GetEmployeeLink(employee.EmployeeId),
                                    Name       = employee.User.Name,
                                    Email      = employee.User.Email,
                                    Descricao  = employee.Descricao,
                                    Image      = employee.User.Image,
                                    Services   = serviceModels,
                                    Company    = companyModel
                                };
                            });
                        }

                        response.Success = true;
                        response.Message = "Funcionários do cliente";
                        response.Result  = employees;
                    }
                    else
                    {
                        response.Message = "Usuário não encontrado";
                    }
                }
                else
                {
                    response.Message = "Guid inválido";
                }
            }catch (Exception e)
            {
                response.Message = $"Não foi possível recuperar os funcionários. \n{e.Message}";
            }

            return(response);
        }