public bool CheckInspactionDriverToDay(int idDriver)
        {
            Driver           driver           = context.Drivers.Include(d => d.InspectionDrivers).FirstOrDefault(d => d.Id == idDriver);
            InspectionDriver inspectionDriver = driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0 ? driver.InspectionDrivers.Last() : null;

            if (inspectionDriver == null)
            {
                driver.IsInspectionDriver      = false;
                driver.IsInspectionToDayDriver = false;
                context.SaveChanges();
            }
            else if (Convert.ToDateTime(inspectionDriver.Date).Date != DateTime.Now.Date)
            {
                if (DateTime.Now.Hour >= 12)
                {
                    driver.IsInspectionDriver      = false;
                    driver.IsInspectionToDayDriver = false;
                }
                else if (DateTime.Now.Hour <= 12 && 6 >= DateTime.Now.Hour)
                {
                    driver.IsInspectionDriver      = true;
                    driver.IsInspectionToDayDriver = false;
                }
                context.SaveChanges();
            }
            return(driver.IsInspectionToDayDriver);
        }
        public async Task <ActionResult> RoadsideInspectionEntry(InspectionDriver model)
        {
            //model.InspectionDate.ToShortDateString().Replace("/", "-");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
            HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "RoadsideInspection/GetInspectionByDate/", model);

            if (responseMessage.IsSuccessStatusCode)
            {
                var result       = responseMessage.Content.ReadAsStringAsync().Result;
                var statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                if (statusResult.Status.Equals(Status.Success.ToString()))
                {
                    List <G_RPT_REG_CP_INSP_IDModel> inspectionsData = JsonConvert.DeserializeObject <List <G_RPT_REG_CP_INSP_IDModel> >(statusResult.Result.ToString());
                    //return Json(inspectionsData, JsonRequestBehavior.AllowGet);
                    var jsonResult = Json(new { data = inspectionsData }, JsonRequestBehavior.AllowGet);
                    jsonResult.MaxJsonLength = int.MaxValue;
                    return(jsonResult);
                }
                else if (statusResult.Status.Equals(Status.Fail.ToString()))
                {
                    return(Json(new { data = new List <G_RPT_REG_CP_INSP_IDModel>() }, JsonRequestBehavior.AllowGet));
                }
            }
            return(View("Error"));
            //return View();
        }
        public int SetInspectionDriver(string token, ref string description, InspectionDriver inspectionDriver, string idDriver)
        {
            IRestResponse response = null;
            string        content  = null;

            try
            {
                string      inspectionDriverjson = JsonConvert.SerializeObject(inspectionDriver);
                RestClient  client  = new RestClient(Config.BaseReqvesteUrl);
                RestRequest request = new RestRequest("Mobile/Driver/SetInspectionDriver", Method.POST);
                client.Timeout = 60000;
                request.AddHeader("Accept", "application/json");
                request.AddParameter("token", token);
                request.AddParameter("idDriver", idDriver);
                request.AddParameter("inspectionDriverStr", inspectionDriverjson);
                response = client.Execute(request);
                content  = response.Content;
            }
            catch (Exception)
            {
                return(4);
            }
            if (content == "" || response.StatusCode == System.Net.HttpStatusCode.NotFound)
            {
                return(4);
            }
            else
            {
                return(GetData(content, ref description));
            }
        }
        public Driver GetDriver(string idInspection)
        {
            InspectionDriver inspectionDriver = context.InspectionDrivers.First(i => i.Id.ToString() == idInspection);

            return(context.Drivers
                   .Include(d => d.InspectionDrivers)
                   .First(d => d.InspectionDrivers.FirstOrDefault(ii => ii.Id == inspectionDriver.Id) != null));
        }
        internal async Task <Trailer> GetTrailerDb(string idDriver)
        {
            Trailer trailer = null;
            Driver  driver  = await context.Drivers.Include(d => d.InspectionDrivers).FirstOrDefaultAsync(d => d.Id.ToString() == idDriver);

            if (driver != null && driver.InspectionDrivers != null && driver.InspectionDrivers.Count != 0)
            {
                InspectionDriver inspectionDriver = driver.InspectionDrivers.Last();
                trailer = await context.Trailers.FirstOrDefaultAsync(t => t.Id == inspectionDriver.IdITrailer);
            }
            return(trailer);
        }
        public async Task <StatusResult> GetInspectionByDate(InspectionDriver inspection)
        {
            StatusResult c = new StatusResult();

            try
            {
                if (!ModelState.IsValid)
                {
                    var errors = ModelState.Where(x => x.Value.Errors.Count > 0).Select(x => x.Value.Errors.Select(y => y.ErrorMessage)).ToList();
                    Log.Error(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", errors.ToArray(), ""));

                    c.Status = Status.BadRequest.ToString();
                    c.Result = BadRequest();
                    return(c);
                }
                if (User.IsInRole(Roles.SuperAdmin) || User.IsInRole(Roles.PortalAdmin) || User.IsInRole(Roles.AccountAdmin))
                {
                    InspectionConfig InspectionConfig = new InspectionConfig();
                    var res = await InspectionConfig.GetInspectionByDate(inspection.CompanyId, inspection.InspectionDate);

                    if (res != null)
                    {
                        Log.Info(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.Success, ""));
                        c.Status = Status.Success.ToString();
                        c.Result = res;
                        return(c);
                    }
                    else
                    {
                        Log.Warn(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.NoResults, ""));
                        c.Status = Status.Fail.ToString();
                        c.Result = "Company is not active";
                        return(c);
                    }
                }
                else
                {
                    Log.Warn(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ErrorMessages.NoAccessDenied, ""));
                    c.Status = Status.NoAccess.ToString();
                    c.Result = "No Access";
                    return(c);
                }
            }
            catch (Exception ex)
            {
                Log.Error(Logfornet.LogMessage(inspection.CompanyId, "GetInspectionByDate", ex.Message, ex.StackTrace));
                c.Status     = ExceptionStatus.SqlException.ToString();
                c.StatusCode = (int)ExceptionStatus.SqlException;
                c.Result     = ex.InnerException;
                return(c);
            }
        }
        internal int[] GetIdTruckAdnTrailarDb(string idDriver)
        {
            int[]            idTruckAdnTrailar = null;
            InspectionDriver inspectionDriver  = context.InspectionDrivers.Last();

            if (inspectionDriver != null)
            {
                idTruckAdnTrailar = new int[] { inspectionDriver.IdITruck, inspectionDriver.IdITrailer };
            }
            else
            {
                idTruckAdnTrailar = new int[0];
            }
            return(idTruckAdnTrailar);
        }
        public async Task <ActionResult> GetCompanyInspection(InspectionDriver model)
        {
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", userData.AccessToken);
            HttpResponseMessage responseMessage = await client.PostAsJsonAsync(_url + "RoadsideInspection/GetInspectionById/", model);

            if (responseMessage.IsSuccessStatusCode)
            {
                var result       = responseMessage.Content.ReadAsStringAsync().Result;
                var statusResult = JsonConvert.DeserializeObject <StatusResult>(result);
                if (statusResult.Status.Equals(Status.Success.ToString()))
                {
                    //G_RPT_REG_CP_INSP_IDModel inspectionsData = JsonConvert.DeserializeObject<G_RPT_REG_CP_INSP_IDModel>(statusResult.Result.ToString());
                    ManualRSIModel inspectionsData = JsonConvert.DeserializeObject <ManualRSIModel>(statusResult.Result.ToString());
                    return(Json(inspectionsData, JsonRequestBehavior.AllowGet));
                }
                else if (statusResult.Status.Equals(Status.Fail.ToString()))
                {
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
            }
            return(View("Error"));
        }
Example #9
0
        public IActionResult ViewInspaction(string idInspection, string idDriver, string date)
        {
            IActionResult actionResult = null;

            try
            {
                string key = null;
                ViewBag.BaseUrl = Config.BaseReqvesteUrl;
                Request.Cookies.TryGetValue("KeyAvtho", out key);
                if (managerDispatch.CheckKey(key))
                {
                    List <Truck>     trucks           = managerDispatch.GetTrucks();
                    List <Trailer>   trailers         = managerDispatch.GetTrailers();
                    InspectionDriver inspectionDriver = managerDispatch.GetInspectionTruck(idInspection);
                    Driver           drivers          = managerDispatch.GetDriver(inspectionDriver.Id.ToString());
                    ViewBag.InspectionTruck = inspectionDriver;
                    ViewBag.Drivers         = drivers;
                    ViewBag.Trailer         = trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITrailer) != null ? $"{trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITrailer).Make}, Plate: {trailers.FirstOrDefault(t => t.Id == inspectionDriver.IdITrailer).Plate}" : "---------------";
                    ViewBag.Truck           = trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck) != null ? $"{trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck).Make} {trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck).Model}, Plate: {trucks.FirstOrDefault(t => t.Id == inspectionDriver.IdITruck).PlateTruk}" : "---------------";
                    ViewBag.SelectData      = date;
                    actionResult            = View("OneInspektion");
                }
                else
                {
                    if (Request.Cookies.ContainsKey("KeyAvtho"))
                    {
                        Response.Cookies.Delete("KeyAvtho");
                    }
                    actionResult = Redirect(Config.BaseReqvesteUrl);
                }
            }
            catch (Exception)
            {
            }
            return(actionResult);
        }
Example #10
0
 public async void SetInspectionDriver(string idDriver, string inspectionDriverStr)
 {
     InspectionDriver inspectionDriver = JsonConvert.DeserializeObject <InspectionDriver>(inspectionDriverStr);
     await sqlCommandApiMobile.SetInspectionDriverInDb(idDriver, inspectionDriver);
 }
Example #11
0
        public int DriverWork(string typeDriver, string token, ref string description, string idDriver, InspectionDriver inspectionDriver = null)
        {
            driverInspecktion = new DriverInspecktion();
            //WaiteNoramalReqvestCount();
            CountReqvest++;
            int stateDriver = 1;

            if (CrossConnectivity.Current.IsConnected)
            {
                if (typeDriver == "SetInspectionDriver")
                {
                    stateDriver = driverInspecktion.SetInspectionDriver(token, ref description, inspectionDriver, idDriver);
                }
                else if (typeDriver == "UpdateInspectionDriver")
                {
                    stateDriver = driverInspecktion.UpdateInspectionDriver(token, ref description, idDriver);
                }
            }
            driverInspecktion = null;
            CountReqvest--;
            return(stateDriver);
        }