Ejemplo n.º 1
0
 private async Task RegisterVehicle(object model)
 {
     using (var testClient = new TestProjetasAPIService(new MediaTypeWithQualityHeaderValue("application/json")))
     {
         var url     = string.Format("{0}{1}", _testProjetasAPIConfig.Value.Url, _testProjetasAPIConfig.Value.VehicleEndPoint);
         var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
         await testClient.PostAsync(url, content);
     }
 }
Ejemplo n.º 2
0
        public async Task <RedirectResult> Delete(int id)
        {
            using (var testClient = new TestProjetasAPIService(new MediaTypeWithQualityHeaderValue("application/json")))
            {
                var url = string.Format("{0}{1}/{2}", _testProjetasAPIConfig.Value.Url, _testProjetasAPIConfig.Value.VehicleEndPoint, id);
                await testClient.DeleteAsync(url);
            }

            return(Redirect("~/Home/Index"));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Edit(int id)
        {
            var ret = new VehicleModel();

            using (var testClient = new TestProjetasAPIService(new MediaTypeWithQualityHeaderValue("application/json")))
            {
                var url = string.Format("{0}{1}/{2}", _testProjetasAPIConfig.Value.Url, _testProjetasAPIConfig.Value.VehicleEndPoint, id);
                ret = Newtonsoft.Json.JsonConvert.DeserializeObject <VehicleModel>(await testClient.GetAsync(url));
            }

            return(View("Index", ret));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> LoadData()
        {
            try
            {
                var draw = HttpContext.Request.Form["draw"].FirstOrDefault();

                var start = Request.Form["start"].FirstOrDefault();

                var length = Request.Form["length"].FirstOrDefault();

                var sortColumn = Request.Form["columns[" + Request.Form["order[0][column]"].FirstOrDefault() + "][name]"].FirstOrDefault();

                var sortColumnDirection = Request.Form["order[0][dir]"].FirstOrDefault();

                var searchValue = Request.Form["search[value]"].FirstOrDefault();

                int pageSize = length != null?Convert.ToInt32(length) : 0;

                int skip = start != null?Convert.ToInt32(start) : 0;

                int recordsTotal = 0;

                using (var testClient = new TestProjetasAPIService(new MediaTypeWithQualityHeaderValue("application/json")))
                {
                    var url         = string.Format("{0}{1}", _testProjetasAPIConfig.Value.Url, _testProjetasAPIConfig.Value.VehicleEndPoint);
                    var vehicleData = Newtonsoft.Json.JsonConvert.DeserializeObject <List <VehicleModel> >(await testClient.GetAsync(url));

                    if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDirection)))
                    {
                        switch (sortColumn)
                        {
                        case "Brand":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.Brand).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.Brand).ToList();
                            }
                            break;

                        case "Model":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.Model).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.Model).ToList();
                            }
                            break;

                        case "Color":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.Color).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.Color).ToList();
                            }
                            break;

                        case "Price":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.Price).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.Price).ToList();
                            }
                            break;

                        case "IsZero":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.IsZero).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.IsZero).ToList();
                            }
                            break;

                        case "RegistrationDate":
                            if (sortColumnDirection == "asc")
                            {
                                vehicleData = vehicleData.OrderBy(x => x.RegistrationDate).ToList();
                            }
                            else
                            {
                                vehicleData = vehicleData.OrderByDescending(x => x.RegistrationDate).ToList();
                            }
                            break;

                        default:
                            break;
                        }
                    }

                    if (!string.IsNullOrEmpty(searchValue))
                    {
                        vehicleData = vehicleData.Where(m => m.Brand.ToUpper().Contains(searchValue.ToUpper()) || m.Color.ToUpper().ToString().Contains(searchValue.ToUpper()) ||
                                                        m.Year.ToString().Contains(searchValue) || m.Model.ToUpper().Contains(searchValue.ToUpper())).ToList();
                    }

                    recordsTotal = vehicleData.Count();

                    var data = vehicleData.Skip(skip).Take(pageSize).ToList();

                    return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data }));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }