예제 #1
0
        public DTO.EditFormData GetData(int userId, int id, int bookingID, int supplierID, string season, 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.FactoryInvoice();
            data.Data.FactoryInvoiceDetails          = new List <DTO.FactoryInvoiceDetail>();
            data.Data.FactoryInvoiceSparepartDetails = new List <DTO.FactoryInvoiceSparepartDetail>();
            data.Data.FactoryInvoiceExtras           = new List <DTO.FactoryInvoiceExtra>();

            data.FactoryOrderDetails          = new List <DTO.FactoryOrderDetailSearchResult>();
            data.FactoryOrderSparepartDetails = new List <DTO.FactoryOrderSparepartDetailSearchResult>();

            //try to get data
            try
            {
                // check permission
                if (id > 0)
                {
                    if (fwFactory.CheckFactoryInvoicePermission(userId, id) == 0)
                    {
                        throw new Exception("Current user don't have access permission for the selected invoice data");
                    }
                }
                else
                {
                    // check booking permission for invoice with product
                    if (bookingID > 0 && fwFactory.CheckBookingPermission(userId, bookingID) == 0)
                    {
                        throw new Exception("Current user don't have access permission for the selected booking data");
                    }
                    if (fwFactory.CheckSupplierPermission(userId, supplierID) == 0)
                    {
                        throw new Exception("Current user don't have access permission for the selected supplier data");
                    }
                }

                using (FactoryInvoiceMngEntities context = CreateContext())
                {
                    if (id <= 0)
                    {
                        if (bookingID > 0)
                        {
                            // get booking info
                            FactoryInvoiceMng_BookingSearchResult_View dbBooking = context.FactoryInvoiceMng_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;
                            }
                            else
                            {
                                throw new Exception("Booking not exists!");
                            }
                        }

                        // get supplier info
                        data.Data.SupplierID = supplierID;
                        Module.Support.DTO.Supplier dtoSupplier = supportFactory.GetSupplier(userId).FirstOrDefault(o => o.SupplierID == supplierID);
                        if (dtoSupplier != null)
                        {
                            data.Data.SupplierUD = dtoSupplier.SupplierUD;
                            data.Data.SupplierNM = dtoSupplier.SupplierNM;
                        }
                        else
                        {
                            throw new Exception("Supplier not exists!");
                        }

                        data.Data.Season = season;
                    }
                    else
                    {
                        data.Data = converter.DB2DTO_FactoryInvoice(context.FactoryInvoiceMng_FactoryInvoice_View
                                                                    .Include("FactoryInvoiceMng_FactoryInvoiceExtra_View")
                                                                    .Include("FactoryInvoiceMng_FactoryInvoiceDetail_View")
                                                                    .Include("FactoryInvoiceMng_FactoryInvoiceSparepartDetail_View")
                                                                    .FirstOrDefault(o => o.FactoryInvoiceID == id));

                        supplierID = data.Data.SupplierID.Value;
                        if (data.Data.BookingID.HasValue)
                        {
                            bookingID = data.Data.BookingID.Value;
                        }
                    }

                    data.FactoryOrderDetails          = converter.DB2DTO_FactoryOrderDetailSearchResultList(context.FactoryInvoiceMng_FactoryOrderDetailSearchResult_View.Where(o => o.BookingID == bookingID && o.SupplierID == supplierID).ToList());
                    data.FactoryOrderSparepartDetails = converter.DB2DTO_FactoryOrderSparepartDetailSearchResultList(context.FactoryInvoiceMng_FactoryOrderSparepartDetailSearchResult_View.Where(o => o.BookingID == bookingID && o.SupplierID == supplierID).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
예제 #2
0
 public DTO.BookingSearchResult DB2DTO_BookingSearchResult(FactoryInvoiceMng_BookingSearchResult_View dbItems)
 {
     return(AutoMapper.Mapper.Map <FactoryInvoiceMng_BookingSearchResult_View, DTO.BookingSearchResult>(dbItems));
 }