Esempio n. 1
0
        public List <DTO.InitInfo> GetInitInfos(Hashtable filters, out Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            string invoiceNo = string.Empty;

            if (filters.ContainsKey("invoiceNo"))
            {
                invoiceNo = filters["invoiceNo"].ToString();
            }
            //try to get data
            try
            {
                using (DraftPackingListMngEntities context = CreateContext())
                {
                    //totalRows = context.DraftPackingList_InitInfo_View.Count();
                    var result = context.DraftPackingList_InitInfo_View.Where(o => o.InvoiceNo.Contains(invoiceNo)).ToList();
                    var data   = converter.DB2DTO_InitInfos(result);
                    return(data);
                }
            }
            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 List <DTO.InitInfo>());
            }
        }
Esempio n. 2
0
        public DTO.DataContainer GetData(Hashtable filters, out Notification notification)
        {
            int id = 0, pID = 0;

            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            if (filters.ContainsKey("id"))
            {
                id = int.Parse(filters["id"].ToString());
            }
            if (filters.ContainsKey("param"))
            {
                pID = int.Parse(filters["param"].ToString());
            }

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

                    if (id > 0)
                    {
                        DraftPackingList_DraftPackingList_View dbItem;
                        dbItem = context.DraftPackingList_DraftPackingList_View.FirstOrDefault(o => o.DraftPackingListID == id);
                        DTO.DraftPackingListDTO DraftPackingListDTO = converter.DB2DTO_DraftPackingList(dbItem);
                        dtoItem.DraftPackingListData = DraftPackingListDTO;
                    }
                    else // new draft
                    {
                        DraftPackingList_NewInfo_View dbInit = context.DraftPackingList_NewInfo_View.Include("DraftPackingList_NewInfoDetail_View").Include("DraftPackingList_NewInfoSparepartDetail_View").FirstOrDefault(o => o.DraftCommercialInvoiceID == pID);
                        dtoItem.DraftPackingListData = converter.DB2DTO_NewInfo(dbInit);

                        //dtoItem.DraftPackingListData.DraftPackingListDetail = converter.DB2DTO_DraftPackingListDetail(context.DraftPackingList_NewInfoDetail_View.Where(o => o.DraftCommercialInvoiceID == pID).ToList());
                        //dtoItem.DraftPackingListData.DraftPackingListSparepartDetail = converter.DB2DTO_DraftPackingListSparepartDetail(context.DraftPackingList_NewInfoSparepartDetail_View.Where(o => o.DraftCommercialInvoiceID == pID).ToList());

                        //DraftPackingList_NewInfo_View dbItem;
                        //dbItem = context.DraftPackingList_NewInfo_View.FirstOrDefault(o => o.DraftCommercialInvoiceID == pID);
                        //DTO.DraftPackingListDTO DraftPackingListDTO = converter.DB2DTO_NewInfo(dbItem);
                        //dtoItem.DraftPackingListData = DraftPackingListDTO;
                    }
                    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.DataContainer());
            }
        }
Esempio n. 3
0
        public bool Delete(int id, out Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (DraftPackingListMngEntities context = CreateContext())
                {
                    DraftPackingList dbItem = context.DraftPackingList.FirstOrDefault(o => o.DraftPackingListID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        List <DraftPackingListDetail> need_delete_details = new List <DraftPackingListDetail>();
                        foreach (DraftPackingListDetail dbDetail in dbItem.DraftPackingListDetail)
                        {
                            need_delete_details.Add(dbDetail);
                        }

                        foreach (var item in need_delete_details)
                        {
                            context.DraftPackingListDetail.Remove(item);
                        }

                        context.DraftPackingList.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);
            }
        }
Esempio n. 4
0
        public override bool UpdateData(int userId, int id, ref object dtoItem, out Notification notification)
        {
            notification = new Notification {
                Type = NotificationType.Success
            };
            DTO.DraftPackingListDTO dtoDraftPackingList = ((Newtonsoft.Json.Linq.JObject)dtoItem).ToObject <DTO.DraftPackingListDTO>();
            try
            {
                using (DraftPackingListMngEntities context = CreateContext())
                {
                    DraftPackingList dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new DraftPackingList();
                        context.DraftPackingList.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.DraftPackingList.FirstOrDefault(o => o.DraftPackingListID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Invoice not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2DB_DraftPackingList(dtoDraftPackingList, ref dbItem);

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

                        context.DraftPackingListDetail.Local.Where(o => o.DraftPackingList == null).ToList().ForEach(o => context.DraftPackingListDetail.Remove(o));


                        context.SaveChanges();

                        Hashtable filter = new Hashtable();
                        filter["id"] = dbItem.DraftPackingListID;
                        dtoItem      = GetData(filter, 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);
            }
        }