Esempio n. 1
0
        // GET: Cars/Edit/5
        public ActionResult Edit(int id)
        {
            //Get car
            var car = ApiCallsService.GetCarRequest(id).Item;

            if (car == null)
            {
                return(NotFound());
            }
            return(View(car));
        }
Esempio n. 2
0
        public ActionResult Create(Car car)
        {
            try
            {
                ApiCallsService.CreateCarRequest(car);

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 3
0
        // GET: Cars/Edit/5
        public ActionResult List()
        {
            //Get filter from session
            var sFilters = HttpContext.Session.GetString("filters");
            var filters  = sFilters == null ? new Filters() : JsonConvert.DeserializeObject <Filters>(sFilters);

            if (filters.State == "any")
            {
                filters.State = null;
            }
            var cars = ApiCallsService.GetCarsRequest(filters);

            return(View(cars.Item));
        }
Esempio n. 4
0
        public ActionResult GetAllBrands(string term)
        {
            try
            {
                var result = ApiCallsService.GetAllBrandsRequest().Item
                             .Where(x => x.StartsWith(term, StringComparison.InvariantCultureIgnoreCase));

                return(new JsonResult(result));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 5
0
        public ActionResult Delete(Car car)
        {
            try
            {
                var response = ApiCallsService.DeleteCarRequest(car);
                //Some error
                if (response == null || !response.Success)
                {
                    return(NotFound("Could not delete"));
                }

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(NotFound("Error"));
            }
        }
Esempio n. 6
0
        public ActionResult Edit(Car car)
        {
            try
            {
                var response = ApiCallsService.UpdateCarRequest(car);
                //Some error
                if (response == null || !response.Success)
                {
                    return(NotFound("Could not edit"));
                }

                return(RedirectToAction(nameof(List)));
            }
            catch
            {
                return(View());
            }
        }
Esempio n. 7
0
        public ActionResult List(Filters filters)
        {
            try
            {
                if (filters.State == "any")
                {
                    filters.State = null;
                }

                var cars = ApiCallsService.GetCarsRequest(filters);

                //Save filter into the session
                HttpContext.Session.SetString("filters", JsonConvert.SerializeObject(filters));
                return(View(cars.Item));
            }
            catch
            {
                return(View());
            }
        }