public ActionResult GetDrives(string pageIndex, string pageSize, FilterDrivesModel filters) { try { var drives = _dataAccessLayer.GetDrives(Convert.ToInt32(pageSize), Convert.ToInt32(pageIndex) - 1, filters); var groupings = drives.GroupBy(x => x.Vlaplan).Select(g => new { Vlaplan = g.Key, Drives = g.ToList(), TotalRows = g.FirstOrDefault().TotalRows }).ToList(); return(Json(new { drives = groupings, JsonRequestBehavior.AllowGet })); } catch (Exception ex) { log.Error(string.Format("Error in GetDrives \n\r : {0} - {1}", ex.Message, ex.StackTrace)); Response.StatusCode = 500; return(Json(new { error = _errorHelper.GetErrorMessage(ex) })); } }
public List <Drive> GetDrives(int pageSize = 0, int pageNumber = 50, FilterDrivesModel filterDrivesModel = null) { return(_driveRepository.GetDrives(pageSize, pageNumber, filterDrivesModel)); }
public List <Drive> GetDrives(int pageSize = 0, int pageNumber = 50, FilterDrivesModel filterDrivesModel = null) { var totalDrivesCount = GetDrivesTotalCount(); using (SqlConnection con = new SqlConnection(ConnectionString)) { using (SqlCommand cmd = new SqlCommand("GetDrives", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@PageNumber", pageNumber); cmd.Parameters.AddWithValue("@PageSize", pageSize); cmd.Parameters.AddWithValue("@FilterDriver", filterDrivesModel.FilterDriver); cmd.Parameters.AddWithValue("@FilterTrail", filterDrivesModel.FilterTrail); cmd.Parameters.AddWithValue("@FilterTruck", filterDrivesModel.FilterTruck); cmd.Parameters.AddWithValue("@FilterVlaplan", filterDrivesModel.FilterVlaplan); cmd.Parameters.AddWithValue("@FilterVlarref", filterDrivesModel.FilterVlarref); con.Open(); var reader = cmd.ExecuteReader(); var drives = new List <Drive>(); while (reader.Read()) { var drive = new Drive(); drive.Id = Guid.Parse(reader["Id"].ToString()); drive.CostsSpecification = reader["CostsSpecification"].ToString(); drive.Date = string.IsNullOrEmpty(reader["Date"].ToString()) ? (DateTime?)null : Convert.ToDateTime(reader["Date"].ToString()); drive.Destination = reader["Destination"].ToString(); drive.Difference = Convert.ToDecimal(reader["Difference"].ToString()); drive.DistanceDFDS = Convert.ToDecimal(reader["DistanceDFDS"].ToString()); drive.DistanceGgl = Convert.ToDecimal(reader["DistanceGpl"].ToString()); drive.DistanceGPS = Convert.ToDecimal(reader["DistanceGPS"].ToString()); drive.FinalGPSKM = Convert.ToDecimal(reader["FinalGPSKM"].ToString()); drive.InitialGPSKM = Convert.ToDecimal(reader["InitialGPSKM"].ToString()); drive.LoadingPlace = reader["LoadingPlace"].ToString(); drive.PayedCosts = Convert.ToDecimal(reader["PayedCosts"].ToString()); drive.PayedCostsPounds = string.IsNullOrEmpty(reader["PayedCostsPounds"].ToString()) ? 0 : Convert.ToDecimal(reader["PayedCostsPounds"].ToString()); drive.Reason = reader["Reason"].ToString(); drive.SettlementCosts = Convert.ToDecimal(reader["SettlementCosts"].ToString()); drive.SettlementCostsPounds = string.IsNullOrEmpty(reader["SettlementCostsPounds"].ToString()) ? 0 : Convert.ToDecimal(reader["SettlementCostsPounds"].ToString()); drive.TotalPayments = Convert.ToDecimal(reader["TotalPayments"].ToString()); drive.TotalPaymentsPounds = string.IsNullOrEmpty(reader["TotalPaymentsPounds"].ToString()) ? 0 : Convert.ToDecimal(reader["TotalPaymentsPounds"].ToString()); drive.Truck = !string.IsNullOrEmpty(reader["Truck"].ToString()) ? Guid.Parse(reader["Truck"].ToString()) : (Guid?)null; drive.Vlaplan = reader["Vlaplan"].ToString(); drive.Vlaref = reader["Vlaref"].ToString(); drive.WeightInTons = Convert.ToDecimal(reader["WeightInTons"].ToString()); drive.Worker = !string.IsNullOrEmpty(reader["Worker"].ToString()) ? Guid.Parse(reader["Worker"].ToString()) : (Guid?)null; drive.WorkerCosts = Convert.ToDecimal(reader["WorkerCosts"].ToString()); drive.WorkerCostsPounds = string.IsNullOrEmpty(reader["WorkerCostsPounds"].ToString()) ? 0 : Convert.ToDecimal(reader["WorkerCostsPounds"].ToString()); drive.FirstName = reader["FirstName"].ToString(); drive.Surname = reader["Surname"].ToString(); drive.TruckRegistrationNumber = reader["RegistrationNumber"].ToString(); drive.LastUpdateByUserName = reader["LastUpdateByUserName"].ToString(); drive.Trailer = reader["Trailer"].ToString(); drive.DriveStatus = !string.IsNullOrEmpty(reader["DriveStatus"].ToString()) ? Guid.Parse(reader["DriveStatus"].ToString()) : (Guid?)null; drive.DriveStatusName = reader["DriveStatusName"].ToString(); drive.TotalRows = totalDrivesCount; drive.EstimatedConsumption = string.IsNullOrEmpty(reader["EstimatedConsumption"].ToString()) ? 0 : Convert.ToDecimal(reader["EstimatedConsumption"].ToString()); drive.CreationDate = DateTime.Parse(reader["CreationDate"].ToString()); drive.DriveTypeName = reader["DriveTypeName"].ToString(); drive.DriveTypeEndName = reader["DriveTypeEndName"].ToString(); drives.Add(drive); } con.Close(); return(drives.OrderBy(x => x.InitialGPSKM).OrderByDescending(x => x.Date).OrderByDescending(x => x.CreationDate).ToList()); } } }