Exemplo n.º 1
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (AVFOutwardInvoiceMngEntities context = CreateContext())
                {
                    AVFOutwardInvoice dbItem = context.AVFOutwardInvoice.FirstOrDefault(o => o.AVFOutwardInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Profile not found!";
                        return(false);
                    }
                    else
                    {
                        foreach (AVFOutwardInvoiceDetail detail in dbItem.AVFOutwardInvoiceDetail.ToArray())
                        {
                            context.AVFOutwardInvoiceDetail.Remove(detail);
                        }
                        context.AVFOutwardInvoice.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            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(false);
            }
        }
Exemplo n.º 2
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Library.DTO.Notification notification)
        {
            DTO.AVFOutwardInvoice dtoAVFOutwardInvoice = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.AVFOutwardInvoice>();
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (AVFOutwardInvoiceMngEntities context = CreateContext())
                {
                    AVFOutwardInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new AVFOutwardInvoice();
                        context.AVFOutwardInvoice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.AVFOutwardInvoice.FirstOrDefault(o => o.AVFOutwardInvoiceID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        // check concurrency
                        if (dbItem.ConcurrencyFlag != null && !dbItem.ConcurrencyFlag.SequenceEqual(Convert.FromBase64String(dtoAVFOutwardInvoice.ConcurrencyFlag_String)))
                        {
                            throw new Exception(Library.Helper.TEXT_CONCURRENCY_CONFLICT);
                        }

                        //convert dto to db
                        converter.DTO2BD(dtoAVFOutwardInvoice, ref dbItem);
                        //remove orphan item
                        context.AVFOutwardInvoiceDetail.Local.Where(o => o.AVFOutwardInvoice == null).ToList().ForEach(o => context.AVFOutwardInvoiceDetail.Remove(o));

                        // processing file
                        //if (dtoAVFOutwardInvoice.PDFFileScan_HasChange)
                        //{
                        //    dbItem.PDFFileScan = fwFactory.CreateNoneImageFilePointer(this._tempFolder, dtoAVFOutwardInvoice.PDFFileScan_NewFile, dtoAVFOutwardInvoice.PDFFileScan);
                        //}

                        dbItem.UpdatedDate = DateTime.Now;
                        dbItem.UpdatedBy   = userId;

                        context.SaveChanges();
                        dtoItem = GetData(dbItem.AVFOutwardInvoiceID, out notification).Data;

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