Exemplo n.º 1
0
        public GetVesselSchedulesResponse GetVesselSchedulesForGrid(GetVesselSchedulesRequest request)
        {
            int totalRecords;
            var data = SortData(request.Search, request.SortingDictionary, out totalRecords);

            if (request.Take != -1)
            {
                data = data.Skip(request.Skip).Take(request.Take);
            }

            return(new GetVesselSchedulesResponse
            {
                TotalRecords = totalRecords,
                VesselSchedules = data.ToList().MapTo <GetVesselSchedulesResponse.VesselScheduleResponse>()
            });
        }
Exemplo n.º 2
0
 public GetVesselSchedulesResponse GetVesselSchedules(GetVesselSchedulesRequest request)
 {
     if (request.OnlyCount)
     {
         return(new GetVesselSchedulesResponse {
             Count = DataContext.VesselSchedules.Count()
         });
     }
     else if (request.allActiveList)
     {
         var query = DataContext.VesselSchedules
                     .Include(x => x.Buyer)
                     .Include(x => x.Vessel)
                     .Include(x => x.Vessel.Measurement)
                     .Select(x => new
         {
             id = x.Id,
             NextLoadingSchedules = x.NextLoadingSchedules.OrderByDescending(y => y.CreatedAt).Take(1).ToList(),
             Buyer       = x.Buyer,
             Vessel      = x.Vessel,
             ETA         = x.ETA,
             ETD         = x.ETD,
             Location    = x.Location,
             SalesType   = x.SalesType,
             Type        = x.Type,
             VesselType  = x.Vessel.Type,
             IsActive    = x.IsActive,
             Cargo       = x.Cargo,
             Measurement = x.Vessel.Measurement.Name,
             Capacity    = x.Vessel.Capacity
         });
         if (request.RemarkDate.HasValue)
         {
             query = DataContext.VesselSchedules
                     .Include(x => x.Buyer)
                     .Include(x => x.Vessel)
                     .Include(x => x.Vessel.Measurement)
                     .Select(x => new
             {
                 id = x.Id,
                 NextLoadingSchedules = x.NextLoadingSchedules.Where(y => y.CreatedAt <= request.RemarkDate.Value).OrderByDescending(y => y.CreatedAt).Take(1).ToList(),
                 Buyer       = x.Buyer,
                 Vessel      = x.Vessel,
                 ETA         = x.ETA,
                 ETD         = x.ETD,
                 Location    = x.Location,
                 SalesType   = x.SalesType,
                 Type        = x.Type,
                 VesselType  = x.Vessel.Type,
                 IsActive    = x.IsActive,
                 Cargo       = x.Cargo,
                 Measurement = x.Vessel.Measurement.Name,
                 Capacity    = x.Vessel.Capacity
             });
         }
         query = query.Where(x => x.IsActive == true);
         if (request.OrderByETDDesc)
         {
             query = query.OrderByDescending(x => x.ETD);
         }
         return(new GetVesselSchedulesResponse
         {
             VesselSchedules = query.Select(
                 x => new GetVesselSchedulesResponse.VesselScheduleResponse
             {
                 id = x.id,
                 Remark = x.NextLoadingSchedules.Count == 1 ? x.NextLoadingSchedules.FirstOrDefault().Remark : null,
                 RemarkDate = x.NextLoadingSchedules.Count == 1 ? x.NextLoadingSchedules.FirstOrDefault().CreatedAt : (DateTime?)null,
                 Buyer = x.Buyer.Name,
                 Vessel = x.Vessel.Name,
                 ETA = x.ETA,
                 ETD = x.ETD,
                 Location = x.Location,
                 SalesType = x.SalesType,
                 Type = x.Type,
                 IsActive = x.IsActive,
                 Cargo = x.Cargo,
                 VesselType = x.VesselType,
                 Measurement = x.Measurement,
                 Capacity = x.Capacity
             }
                 ).ToList()
         });
     }
     else
     {
         var query = DataContext.VesselSchedules.Include(x => x.Buyer)
                     .Include(x => x.Vessel);
         if (!string.IsNullOrEmpty(request.Term))
         {
             query = query.Where(x => x.Vessel.Name.Contains(request.Term));
         }
         query = query.OrderByDescending(x => x.Id).Skip(request.Skip).Take(request.Take);
         return(new GetVesselSchedulesResponse
         {
             VesselSchedules = query.ToList().MapTo <GetVesselSchedulesResponse.VesselScheduleResponse>()
         });
     }
 }