コード例 #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 (CostInvoiceMngEntities context = CreateContext())
                {
                    CostInvoice dbItem = context.CostInvoice.FirstOrDefault(o => o.CostInvoiceID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        context.CostInvoice.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);
            }
        }
コード例 #2
0
        public override bool UpdateData(int id, ref DTO.CostInvoiceMng.CostInvoice dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (CostInvoiceMngEntities context = CreateContext())
                {
                    CostInvoice dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new CostInvoice();
                        context.CostInvoice.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.CostInvoice.FirstOrDefault(o => o.CostInvoiceID == id);
                    }

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

                        converter.DTO2DB_CostInvoice(dtoItem, ref dbItem);

                        //remove orphan item
                        context.CostInvoiceDetailExtend.Local.Where(o => o.CostInvoiceDetail == null).ToList().ForEach(o => context.CostInvoiceDetailExtend.Remove(o));
                        context.CostInvoiceDetail.Local.Where(o => o.CostInvoice == null).ToList().ForEach(o => context.CostInvoiceDetail.Remove(o));

                        //save data
                        context.SaveChanges();

                        //reload data
                        dtoItem = GetData(dbItem.CostInvoiceID, out notification);

                        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);
            }
        }