public DTO.PackingListMng.PackingList DB2DTO_InitInfo(PackingListMng_InitInfo_View dbItem)
 {
     DTO.PackingListMng.PackingList dtoItem = AutoMapper.Mapper.Map <PackingListMng_InitInfo_View, DTO.PackingListMng.PackingList>(dbItem);
     return(dtoItem);
 }
Example #2
0
        /*
         * Custom functions
         */

        public DTO.PackingListMng.DataContainer GetDataContainer(int id, int purchasingInvoiceID, int iRequesterID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            //try to get data
            try
            {
                using (PackingListMngEntities context = CreateContext())
                {
                    DTO.PackingListMng.DataContainer dtoItem = new DTO.PackingListMng.DataContainer();

                    if (id > 0)
                    {
                        //check permission on invoice
                        if (fwFactory.CheckPackingListPermission(iRequesterID, id) == 0)
                        {
                            throw new Exception("You do not have access permission on this packing list");
                        }

                        PackingListMng_PackingList_View dbItem;
                        dbItem = context.PackingListMng_PackingList_View
                                 .Include("PackingListMng_PackingListDetail_View")
                                 .Include("PackingListMng_PackingListDetailExtend_View")
                                 .Include("PackingListMng_ECommercialInvoice_View")
                                 .Include("PackingListMng_PackingListSparepartDetail_View")
                                 .FirstOrDefault(o => o.PackingListID == id);
                        DTO.PackingListMng.PackingList PackingListDTO = converter.DB2DTO_PackingList(dbItem);
                        dtoItem.PackingListData = PackingListDTO;
                    }
                    else
                    {
                        //check permission on invoice
                        if (fwFactory.CheckPurchasingInvoicePermission(iRequesterID, purchasingInvoiceID) == 0)
                        {
                            throw new Exception("You do not have access permission on this invoice to create packing list");
                        }
                        dtoItem.PackingListData = new DTO.PackingListMng.PackingList();
                        //init data
                        PackingListMng_InitInfo_View dbInit = context.PackingListMng_InitInfo_View.Include("PackingListMng_InitInfoDetail_View").Include("PackingListMng_InitInfoSparepartDetail_View").FirstOrDefault(o => o.PurchasingInvoiceID == purchasingInvoiceID);
                        dtoItem.PackingListData = converter.DB2DTO_InitInfo(dbInit);

                        //init other info
                        dtoItem.PackingListData.PackingListUD           = dbInit.InvoiceNo;
                        dtoItem.PackingListData.PackingListDateFormated = DateTime.Now.ToString("dd/MM/yyyy");

                        int i = -1;
                        foreach (var item in dtoItem.PackingListData.PackingListDetails)
                        {
                            item.PackingListDetailID = i;
                            i--;
                        }

                        i = -1;
                        foreach (var item in dtoItem.PackingListData.PackingListSparepartDetails)
                        {
                            item.PackingListSparepartDetailID = i;
                            i--;
                        }

                        dtoItem.PackingListData.PackingListDetailExtends = new List <DTO.PackingListMng.PackingListDetailExtend>();
                    }
                    return(dtoItem);
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                notification.DetailMessage.Add(ex.Message);
                if (ex.GetBaseException() != null)
                {
                    notification.DetailMessage.Add(ex.GetBaseException().Message);
                }
                return(new DTO.PackingListMng.DataContainer());
            }
        }