Esempio n. 1
0
        //HOME PAGE
        public async Task <IActionResult> EquipamentosHome()
        {
            bool getValue = Request.Cookies.TryGetValue("token", out string token);

            if (getValue)
            {
                List <Cliente> listaClientes = new List <Cliente>();
                int            nrCliente     = 0;

                using (var httpClient = new HttpClient())
                {
                    Uri uri_clientes = new Uri(URL_API);
                    uri_clientes = new Uri(uri_clientes, "paulosautoapi/utilizador/cliente");

                    using (var response = await httpClient.GetAsync(uri_clientes))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        listaClientes = JsonConvert.DeserializeObject <List <Cliente> >(apiResponse);
                    }

                    foreach (var cliente in listaClientes)
                    {
                        Request.Cookies.TryGetValue("email", out string email);
                        if (cliente.email == email)
                        {
                            nrCliente = cliente.numeroCliente;
                            SetCookie("nrCliente", Convert.ToString(nrCliente), null);
                        }
                    }
                }

                //cria e recebe lista de elementos da API
                List <Equipamento> listaEquipamentos = new List <Equipamento>();
                using (var httpClient = new HttpClient())
                {
                    Uri uri_equipamentos = new Uri(URL_API);
                    uri_equipamentos = new Uri(uri_equipamentos, "paulosautoapi/clientes/equipamentos/" + nrCliente);

                    using (var response = await httpClient.GetAsync(uri_equipamentos))
                    {
                        string apiResponse = await response.Content.ReadAsStringAsync();

                        listaEquipamentos = JsonConvert.DeserializeObject <List <Equipamento> >(apiResponse);
                    }
                }

                var HomeFilterVM = new HomeFilter
                {
                    listaEquipamentos = listaEquipamentos
                };

                return(View(HomeFilterVM));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public async Task <PagedResultDto <CompanyPostModel> > GetAllCompanyPostPaging(HomeFilter input)
        {
            var companyQuery = WorkScope.GetAll <Company>()
                               .Include(x => x.Posts)
                               .Include(x => x.Assets)
                               .WhereIf(input.IsHot.HasValue, x => x.IsHot == input.IsHot)
                               .Where(x => x.Posts.Any())
                               .OrderByDescending(x => x.CreationTime)
                               .PageBy((input.CurrentPage - 1) * input.PageSize, input.PageSize)
                               .Select(x => new
            {
                Company   = x,
                Thumbnail = x.Assets.Where(p => p.FileType == FileType.Thumbnail)
                            .Select(p => new ObjectFile
                {
                    Id       = p.Id,
                    FileType = p.FileType,
                    Path     = p.Path
                }).FirstOrDefault(),
                Post = x.Posts.OrderByDescending(p => p.CreationTime)
                       .FirstOrDefault()
            });

            int totalCount = await companyQuery.CountAsync();

            DateTime localTime = GetLocalTime();

            var result = await companyQuery.Select(x => new CompanyPostModel
            {
                FullCompanyName  = x.Company.FullNameCompany,
                Location         = x.Company.Location,
                CompanyId        = x.Company.Id,
                MaxSalary        = x.Post.MaxMoney,
                MinSalary        = x.Post.MinMoney,
                MoneyType        = x.Post.MoneyType,
                PostId           = x.Post.Id,
                PostUrl          = x.Post.PostUrl,
                Title            = x.Post.Title,
                Treatment        = x.Company.Treatment,
                Thumbnail        = x.Thumbnail,
                TimeCreateNewJob = (int)(localTime - x.Post.CreationTime).TotalHours
            }).ToListAsync();

            return(new PagedResultDto <CompanyPostModel>(totalCount, result));
        }
Esempio n. 3
0
        public async Task <ListResult <Hely> > ListHome(HomeFilter filter, int pageSize, int pageNum)
        {
            var lista = this.Hely.Where(x => x.Meddig == null && x.EszkozHely.Tipus.LehetNegativ == false && x.Mennyiseg > 0);

            if (filter != null)
            {
                if (!string.IsNullOrEmpty(filter.Kereses))
                {
                    lista = lista.Where(x => x.Eszkoz.Nev.Contains(filter.Kereses) ||
                                        x.EszkozHely.Nev.Contains(filter.Kereses));
                }

                if (filter.Sorrend != null && filter.Sorrend.Count > 0)
                {
                    foreach (var c in filter.Sorrend)
                    {
                        if (c.Item1 == "EszkozID")
                        {
                            if (c.Item2 == "A")
                            {
                                lista = lista.OrderBy(c => c.Eszkoz.Nev);
                            }
                            else
                            {
                                lista = lista.OrderByDescending(c => c.Eszkoz.Nev);
                            }
                        }

                        if (c.Item1 == "EszkozHelyID")
                        {
                            if (c.Item2 == "A")
                            {
                                lista = lista.OrderBy(c => c.EszkozHely.Nev);
                            }
                            else
                            {
                                lista = lista.OrderByDescending(c => c.EszkozHely.Nev);
                            }
                        }

                        if (c.Item1 == "Mennyiseg")
                        {
                            if (c.Item2 == "A")
                            {
                                lista = lista.OrderBy(c => c.Mennyiseg);
                            }
                            else
                            {
                                lista = lista.OrderByDescending(c => c.Mennyiseg);
                            }
                        }
                        if (c.Item1 == "Mikortol")
                        {
                            if (c.Item2 == "A")
                            {
                                lista = lista.OrderBy(c => c.Mikortol);
                            }
                            else
                            {
                                lista = lista.OrderByDescending(c => c.Mikortol);
                            }
                        }
                    }
                }
            }

            ListResult <Hely> res = new ListResult <Hely>();

            res.Total = await lista.CountAsync();

            res.Data = await lista
                       .Skip((pageNum - 1) *pageSize)
                       .Take(pageSize)
                       .Include(t => t.Eszkoz)
                       .Include(t => t.EszkozHely)
                       .ToListAsync();

            return(res);
        }