Beispiel #1
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();
        }