示例#1
0
        public bool DeleteData(int id, int iRequesterID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                //check permission on invoice
                if (fwFactory.CheckPackingListPermission(iRequesterID, id) == 0)
                {
                    throw new Exception("You do not have access permission on this packing list");
                }
                using (PackingListMngEntities context = CreateContext())
                {
                    PackingList dbItem = context.PackingList.FirstOrDefault(o => o.PackingListID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        List <PackingListDetail> need_delete_details = new List <PackingListDetail>();
                        foreach (PackingListDetail dbDetail in dbItem.PackingListDetail)
                        {
                            need_delete_details.Add(dbDetail);
                        }

                        List <PackingListDetailExtend> need_delete_detailextends = new List <PackingListDetailExtend>();
                        foreach (PackingListDetailExtend dbDetailExtend in dbItem.PackingListDetailExtend)
                        {
                            need_delete_detailextends.Add(dbDetailExtend);
                        }

                        foreach (var item in need_delete_details)
                        {
                            context.PackingListDetail.Remove(item);
                        }
                        foreach (var item in need_delete_detailextends)
                        {
                            context.PackingListDetailExtend.Remove(item);
                        }

                        context.PackingList.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 bool UpdateData(int id, ref DTO.PackingListMng.PackingList dtoItem, int iRequesterID, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (PackingListMngEntities context = CreateContext())
                {
                    PackingList dbItem = null;
                    if (id == 0)
                    {
                        //check permission on invoice
                        if (fwFactory.CheckPurchasingInvoicePermission(iRequesterID, dtoItem.PurchasingInvoiceID.Value) == 0)
                        {
                            throw new Exception("You do not have access permission on this invoice to create packing list");
                        }
                        dbItem = new PackingList();
                        context.PackingList.Add(dbItem);
                    }
                    else
                    {
                        //check permission on invoice
                        if (fwFactory.CheckPackingListPermission(iRequesterID, id) == 0)
                        {
                            throw new Exception("You do not have access permission on this packing list");
                        }
                        dbItem = context.PackingList.FirstOrDefault(o => o.PackingListID == 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_PackingList(dtoItem, ref dbItem);

                        if (id == 0)
                        {
                            dbItem.CreatedBy   = dtoItem.UpdatedBy;
                            dbItem.CreatedDate = DateTime.Now;
                        }
                        else
                        {
                            dbItem.UpdatedBy   = dtoItem.UpdatedBy;
                            dbItem.UpdatedDate = DateTime.Now;
                        }

                        context.PackingListDetail.Local.Where(o => o.PackingList == null).ToList().ForEach(o => context.PackingListDetail.Remove(o));
                        context.PackingListSparepartDetail.Local.Where(o => o.PackingList == null).ToList().ForEach(o => context.PackingListSparepartDetail.Remove(o));
                        context.PackingListDetailExtend.Local.Where(o => o.PackingList == null).ToList().ForEach(o => context.PackingListDetailExtend.Remove(o));

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

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                if (ex.InnerException != null && !string.IsNullOrEmpty(ex.InnerException.Message))
                {
                    notification.DetailMessage.Add(ex.InnerException.Message);
                }
                return(false);
            }
        }