Ejemplo n.º 1
0
        public override bool UpdateData(int id, ref DTO.ForwarderInvoiceMng.ForwarderInvoice dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try {
                using (ForwarderInvoiceMngEntities context = CreateContext())
                {
                    ForwarderInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ForwarderInvoice();
                        context.ForwarderInvoices.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ForwarderInvoices.FirstOrDefault(o => o.ForwarderInvoiceID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Forwarder Invoice not found";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD(dtoItem, ref dbItem);
                        context.SaveChanges();

                        // processing file
                        if (dtoItem.PDFFileScan_HasChange)
                        {
                            dbItem.PDFFileScan = fwFactory.CreateNoneImageFilePointer(this._TempFolder, dtoItem.PDFFileScan_NewFile, dtoItem.PDFFileScan);
                        }
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ForwarderInvoiceID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;

                return(false);
            }
        }
Ejemplo n.º 2
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                using (ForwarderInvoiceMngEntities context = CreateContext())
                {
                    ForwarderInvoice dbItem = context.ForwarderInvoices.FirstOrDefault(o => o.ForwarderInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Forwarder Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        context.ForwarderInvoices.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }