Exemple #1
0
        public string TransferRequestDTOGetByCriterion(string d, string bti, string ri)
        {
            DateTime?date = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            var busTypeId = -1;

            try
            {
                busTypeId = Int32.Parse(bti);
            }
            catch { }
            var listBusType = TransferRequestByDateBLL.BusTypeGetAllById(busTypeId).Future().ToList();
            var routeId     = -1;

            try
            {
                routeId = Int32.Parse(ri);
            }
            catch { }
            var listRoute    = TransferRequestByDateBLL.RouteGetAllById(routeId).Future().ToList();
            var listRouteDTO = new List <RouteDTO>();

            foreach (var route in listRoute)
            {
                var listBusTypeDTO = new List <BusTypeDTO>();
                var routeDTO       = new RouteDTO()
                {
                    Id   = route.Id,
                    Name = route.Name,
                    Way  = route.Way,
                };
                foreach (var busType in listBusType)
                {
                    var busTypeDTO = new BusTypeDTO()
                    {
                        Id   = busType.Id,
                        Name = busType.Name,
                        HaveBookingNoGroup = BusTypeCheckBookingHaveNoGroup(busType, route, date),
                        HaveNoBooking      = false,
                    };
                    var listBusByDateDTO = new List <BusByDateDTO>();
                    var listBusByDate    = TransferRequestByDateBLL.BusByDateGetAllByCriterion(date, busType, route, route.Way)
                                           .OrderBy(y => y.Group).Asc.Future().ToList();
                    listBusByDate.ForEach(busByDate =>
                    {
                        var listBookingBusByDate = TransferRequestByDateBLL.BookingBusByDateGetAllByCriterion(busByDate).Future().ToList();
                        var listBooking          = listBookingBusByDate.Select(x => x.Booking).Distinct().ToList();
                        int?supplierId           = null;
                        if (busByDate.Supplier != null)
                        {
                            supplierId = busByDate.Supplier.Id;
                        }
                        var busByDateDTO = new BusByDateDTO()
                        {
                            Id           = busByDate.Id,
                            Group        = busByDate.Group,
                            Driver_Name  = busByDate.Driver_Name,
                            Driver_Phone = busByDate.Driver_Phone,
                            Adult        = listBooking.Select(x => x.Adult).Sum(),
                            Child        = listBooking.Select(x => x.Child).Sum(),
                            Baby         = listBooking.Select(x => x.Baby).Sum(),
                            SupplierId   = supplierId,
                            RouteName    = busByDate.Route != null ? busByDate.Route.Name : "",
                            BusTypeName  = busByDate.BusType != null ? busByDate.BusType.Name : "",
                        };
                        foreach (var busByDateGuide in busByDate.BusByDatesGuides)
                        {
                            var guide         = busByDateGuide.Guide;
                            GuideDTO guideDTO = null;
                            if (guide != null && guide.Id > 0)
                            {
                                guideDTO = new GuideDTO()
                                {
                                    Id    = guide.Id,
                                    Name  = guide.Name,
                                    Phone = guide.Phone,
                                };
                            }
                            var busByDateGuideDTO = new BusByDateGuideDTO()
                            {
                                BusByDateDTO = busByDateDTO,
                                GuideDTO     = guideDTO
                            };
                            busByDateDTO.BusByDatesGuidesDTO.Add(busByDateGuideDTO);
                        }
                        listBusByDateDTO.Add(busByDateDTO);
                    });
                    busTypeDTO.ListBusByDateDTO = listBusByDateDTO;
                    listBusTypeDTO.Add(busTypeDTO);
                }
                routeDTO.ListBusTypeDTO = listBusTypeDTO;
                listRouteDTO.Add(routeDTO);
            }
            var transferRequestDTO = new TransferRequestDTO();

            transferRequestDTO.ListRouteDTO = listRouteDTO;
            Dispose();
            return(JsonConvert.SerializeObject(transferRequestDTO));
        }
Exemple #2
0
        public void TransferRequestDTOSaveOrUpdate(TransferRequestDTO tr, string d)
        {
            var      listRouteDTO = tr.ListRouteDTO;
            DateTime?date         = null;

            try
            {
                date = DateTime.ParseExact(d, "dd/MM/yyyy", CultureInfo.InvariantCulture);
            }
            catch { }
            foreach (var routeDTO in listRouteDTO)
            {
                var route = TransferRequestByDateBLL.RouteGetById(routeDTO.Id);
                foreach (var busTypeDTO in routeDTO.ListBusTypeDTO)
                {
                    var busType = TransferRequestByDateBLL.BusTypeGetById(busTypeDTO.Id);
                    foreach (var busByDateDTO in busTypeDTO.ListBusByDateDTO)
                    {
                        //Tạo hoặc update Busbydate
                        var busByDate = TransferRequestByDateBLL.BusByDateGetById(busByDateDTO.Id);//Tìm Busbydate theo id của BusbydateDTO
                        if (busByDate == null)
                        {
                            busByDate = new BusByDate();//Nếu không có tạo mới
                        }
                        //--//
                        //Update thông tin vào Busbydate vừa lấy được
                        busByDate.Group   = busByDateDTO.Group;
                        busByDate.BusType = busType;
                        busByDate.Route   = route;
                        busByDate.Date    = date;
                        var supplierId = busByDateDTO.SupplierId ?? 0;
                        var supplier   = TransferRequestByDateBLL.AgencyGetById(supplierId);
                        if (supplier != null && supplier.Id <= 0)
                        {
                            supplier = null;
                        }
                        busByDate.Supplier     = supplier;
                        busByDate.Driver_Name  = busByDateDTO.Driver_Name;
                        busByDate.Driver_Phone = busByDateDTO.Driver_Phone;
                        //Lấy thông tin guide gắn vào bus
                        busByDate.BusByDatesGuides.Clear();
                        foreach (var busByDateGuideDTO in busByDateDTO.BusByDatesGuidesDTO)
                        {
                            var guideId = 0;
                            if (busByDateGuideDTO.GuideDTO != null)
                            {
                                guideId = busByDateGuideDTO.GuideDTO.Id ?? 0;
                            }
                            Guide guide = null;
                            guide = transferRequestByDateBLL.GuideGetById(guideId);
                            if (guide != null && guide.Id <= 0)
                            {
                                guide = null;
                            }
                            var busByDateGuide = new BusByDateGuide()
                            {
                                Guide     = guide,
                                BusByDate = busByDate,
                            };
                            busByDate.BusByDatesGuides.Add(busByDateGuide);
                        }
                        TransferRequestByDateBLL.BusByDateSaveOrUpdate(busByDate);
                        //--//
                        //Xóa Busbydate nếu đã được lưu nhưng bị đánh dấu deleted
                        if (busByDateDTO.Deleted)
                        {
                            if (busByDate.Id > 0)
                            {
                                TransferRequestByDateBLL.BusByDateDelete(busByDate);
                                continue;
                            }
                        }
                        //--//
                        BusByDateCloneForRouteBackNextDay(busByDate);
                    }
                }
            }
            Dispose();
        }