Exemplo n.º 1
0
        public async Task <IActionResult> AddLocation(LocationViewModel request, string answer)
        {
            if (!string.IsNullOrWhiteSpace(answer))
            {
                switch (answer)
                {
                case "Submit":
                    try
                    {
                        request.Token = _cache.Get("Token-" + _memoryCache.Get <string>("UserId"));
                        var result = await _requestHandler.ProcessingRequest(request, ActionMethodType.RecordLocation);

                        var response       = result.Content.ReadAsStringAsync();
                        var serverResponse = JsonConvert.DeserializeObject <ServerResponse>(response.Result);
                        if (serverResponse.RespCode == 200)
                        {
                            ViewBag.Status = "is successful.";
                        }
                        else
                        {
                            ViewBag.Status = serverResponse.RespDesc;
                        }
                    }
                    catch (RedisConnectionException redisConnectionException)
                    {
                        ViewBag.Status = "Oops! Please contact with administrator for connecting Redis Server.";
                    }
                    break;

                case "Reset":
                    return(RedirectToAction("AddLocation"));
                }
            }
            var vehicles       = _requestHandler.ProcessingRequest(ActionMethodType.GetAllVehicles);
            var listOfVehicles = JsonConvert.DeserializeObject <List <VehicleViewModel> >(vehicles.Result);

            ViewBag.ListOfVehicles = listOfVehicles;

            var locationResult  = _requestHandler.ProcessingRequest(ActionMethodType.GetAllLocations);
            var listOfLocations = JsonConvert.DeserializeObject <List <LocationViewModel> >(locationResult.Result);

            ViewBag.listOfLocations = listOfLocations;

            return(View(request));
        }