// GET: api/Home public MainDto Get() { var cities = _context.Cities.Select(a => new CityDto { Id = a.Id, Name = a.Name }); var offices = _context.Offices.Select(a => new OfficeDto { Id = a.Id, Rate = a.Rate ?? 5, Number = a.Number }); var services = _context.Services.Select(a => new ServiceDto { Id = a.Id, Name = a.Name, Types = _context.TypeOfService.Select(aa => new TypeDto { Id = aa.Id, Name = aa.Name, FK_Service = aa.Service.Id }).ToList() }); MainDto homeVM = new MainDto { Cities = cities, Offices = offices, Services = services }; return(homeVM); }
public async Task <MainDto> LoginGet() { var news = await _newsRepository.GetAllAsync(); var employees = await _employeeRepository.GetAllAsync(); var votes = await _voteRepository.GetAllAsync(); if (votes != null) { foreach (var temp in votes) { double summ = 0; temp.voteLists = _context.VoteLists.OrderBy(e => e.Id).Where(e => e.VoteId == temp.Id).ToList(); foreach (var tempx in temp.voteLists) { summ += tempx.Count; tempx.Vote = null; } foreach (var tempx in temp.voteLists) { if (summ != 0) { tempx.Count = (int)((tempx.Count / summ) * 100); } } } } var users = new List <EmployeeInfo>(); if (employees != null) { foreach (var temp in employees) { var user = await _systemContext.Users .Include(e => e.Profile) .FirstOrDefaultAsync(e => e.Id == temp.UserId); string image = "assets/images/avatar.jpg"; if (user != null) { if (user.Profile.Photo != null) { image = "data:image/jpeg;base64," + Convert.ToBase64String(user?.Profile?.Photo); } } var emp = new EmployeeInfo { Email = temp?.Contact?.Email ?? "", PhoneNumber = temp?.Contact?.MobilePhoneNumber ?? "", FullName = temp?.Passport?.ToFio() ?? "", Avatar = image, }; users.Add(emp); } } var main = new MainDto { News = news, Votes = votes, Employees = users, CountEmployees = employees.Count, CountOnlineEmployees = UserHandler.ConnectedIds.Count }; return(main); }