Exemplo n.º 1
0
 public DTO.LoadingPlan DB2DTO_LoadingPlan(FactoryLoadingPlanMng_LoadingPlan_View dbItem)
 {
     return(AutoMapper.Mapper.Map <FactoryLoadingPlanMng_LoadingPlan_View, DTO.LoadingPlan>(dbItem));
 }
Exemplo n.º 2
0
        public DTO.EditFormData GetData(int userId, int id, int bookingID, int factoryID, int parentID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.EditFormData data = new DTO.EditFormData();
            data.Data = new DTO.LoadingPlan();
            data.Data.LoadingPlanDetails          = new List <DTO.LoadingPlanDetail>();
            data.Data.LoadingPlanSparepartDetails = new List <DTO.LoadingPlanSparepartDetail>();
            data.ContainerTypes = new List <Support.DTO.ContainerType>();

            //try to get data
            try
            {
                // check permission
                if (id > 0)
                {
                    if (fwFactory.CheckLoadingPlanPermission(userId, id) == 0)
                    {
                        throw new Exception("Current user don't have access permission for the selected loading plan data");
                    }
                }
                else
                {
                    if (bookingID > 0)
                    {
                        if (fwFactory.CheckBookingPermission(userId, bookingID) == 0)
                        {
                            throw new Exception("Current user don't have access permission for the selected booking data");
                        }
                    }
                }

                using (FactoryLoadingPlanMngEntities context = CreateContext())
                {
                    if (id == 0)
                    {
                        if (bookingID <= 0 && parentID <= 0)
                        {
                            throw new Exception("Booking/Parent loading plan is invalid!");
                        }

                        // get booking info
                        if (bookingID > 0)
                        {
                            FactoryLoadingPlanMng_BookingSearchResult_View dbBooking = context.FactoryLoadingPlanMng_BookingSearchResult_View.FirstOrDefault(o => o.BookingID == bookingID);
                            if (dbBooking != null)
                            {
                                DTO.BookingSearchResult dtoBooking = converter.DB2DTO_BookingSearchResult(dbBooking);
                                data.Data.BookingID   = bookingID;
                                data.Data.BookingUD   = dtoBooking.BookingUD;
                                data.Data.BLNo        = dtoBooking.BLNo;
                                data.Data.Season      = dtoBooking.Season;
                                data.Data.CutOffDate  = dtoBooking.CutOffDate;
                                data.Data.Feeder      = dtoBooking.Feeder;
                                data.Data.Vessel      = dtoBooking.Vessel;
                                data.Data.ETA         = dtoBooking.ETA;
                                data.Data.ETD         = dtoBooking.ETD;
                                data.Data.ClientUD    = dtoBooking.ClientUD;
                                data.Data.ForwarderNM = dtoBooking.ForwarderNM;
                            }
                            else
                            {
                                throw new Exception("Booking not exists!");
                            }
                        }

                        // get parent loading plan info
                        if (parentID > 0)
                        {
                            FactoryLoadingPlanMng_LoadingPlan_View dbLoadingPlan = context.FactoryLoadingPlanMng_LoadingPlan_View.FirstOrDefault(o => o.LoadingPlanID == parentID);
                            if (dbLoadingPlan != null)
                            {
                                if (dbLoadingPlan.ParentID.HasValue && dbLoadingPlan.ParentID.Value > 1)
                                {
                                    throw new Exception("Invalid parent loading plan!");
                                }
                                data.Data.BookingID   = dbLoadingPlan.BookingID;
                                data.Data.BookingUD   = dbLoadingPlan.BookingUD;
                                data.Data.BLNo        = dbLoadingPlan.BLNo;
                                data.Data.Season      = dbLoadingPlan.Season;
                                data.Data.CutOffDate  = dbLoadingPlan.CutOffDate.HasValue ? dbLoadingPlan.CutOffDate.Value.ToString("dd/MM/yyyy") : "";
                                data.Data.Feeder      = dbLoadingPlan.Feeder;
                                data.Data.Vessel      = dbLoadingPlan.Vessel;
                                data.Data.ETA         = dbLoadingPlan.ETA.HasValue ? dbLoadingPlan.ETA.Value.ToString("dd/MM/yyyy") : "";
                                data.Data.ETD         = dbLoadingPlan.ETD.HasValue ? dbLoadingPlan.ETD.Value.ToString("dd/MM/yyyy") : "";
                                data.Data.ClientUD    = dbLoadingPlan.ClientUD;
                                data.Data.ForwarderNM = dbLoadingPlan.ForwarderNM;

                                data.Data.ContainerNo           = dbLoadingPlan.ContainerNo;
                                data.Data.ContainerTypeID       = dbLoadingPlan.ContainerTypeID;
                                data.Data.SealNo                = dbLoadingPlan.SealNo;
                                data.Data.ParentContainerNo     = dbLoadingPlan.ContainerNo;
                                data.Data.ParentContainerTypeNM = dbLoadingPlan.ContainerTypeNM;
                                data.Data.ParentLoadingPlanUD   = dbLoadingPlan.LoadingPlanUD;
                                data.Data.ParentSealNo          = dbLoadingPlan.SealNo;

                                data.Data.ParentID = parentID;
                            }
                            else
                            {
                                throw new Exception("Parent loading plan not exists!");
                            }
                        }

                        data.Data.FactoryID = factoryID;

                        // get factory info
                        Module.Support.DTO.Factory dtoFactory = supportFactory.GetFactory(userId).FirstOrDefault(o => o.FactoryID == factoryID);
                        if (dtoFactory != null)
                        {
                            data.Data.FactoryUD = dtoFactory.FactoryUD;
                        }
                        else
                        {
                            throw new Exception("Factory not exists!");
                        }
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_LoadingPlan(context.FactoryLoadingPlanMng_LoadingPlan_View
                                                                 .Include("FactoryLoadingPlanMng_LoadingPlanDetail_View")
                                                                 .Include("FactoryLoadingPlanMng_LoadingPlanSparepartDetail_View")
                                                                 .FirstOrDefault(o => o.LoadingPlanID == id));
                    }

                    data.ContainerTypes = supportFactory.GetContainerType();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }