예제 #1
0
        public override bool Approve(int id, ref DTO.ShippingInstructionMng.ShippingInstruction dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };

            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    if (dbItem != null)
                    {
                        dbItem.IsConfirmed   = true;
                        dbItem.ConfirmedBy   = dtoItem.UpdatedBy;
                        dbItem.ConfirmedDate = DateTime.Now;
                        context.SaveChanges();

                        dtoItem = GetData(id, out notification).Data;
                        return(true);
                    }
                    else
                    {
                        throw new Exception("Shipping instruction not found!");
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
예제 #2
0
        public override bool UpdateData(int id, ref DTO.ShippingInstructionMng.ShippingInstruction dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new ShippingInstruction();
                        context.ShippingInstruction.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Shipping instruction 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);
                        }

                        // reset default
                        if (dtoItem.IsDefault.HasValue && dtoItem.IsDefault.Value)
                        {
                            int        ClientID       = dtoItem.ClientID.Value;
                            List <int> InstructionIDs = context.ShippingInstructionMng_ShippingInstruction_View.Where(o => o.ClientID == ClientID).Select(o => o.ShippingInstructionID).ToList();
                            context.ShippingInstruction.Where(o => InstructionIDs.Contains(o.ShippingInstructionID)).ToList().ForEach(o => o.IsDefault = null);
                        }

                        converter.DTO2DB(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.ShippingInstructionID, out notification).Data;
                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message, Type = Library.DTO.NotificationType.Error
                };
                return(false);
            }
        }
예제 #3
0
        public override DTO.ShippingInstructionMng.EditFormData GetData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ShippingInstructionMng.EditFormData data = new DTO.ShippingInstructionMng.EditFormData();
            data.Data           = new DTO.ShippingInstructionMng.ShippingInstruction();
            data.Clients        = new List <DTO.Support.Client>();
            data.ConsigneeTypes = new List <DTO.Support.ConsigneeType>();
            data.Countries      = new List <DTO.Support.ClientCountry>();
            data.Forwarders     = new List <DTO.Support.Forwarder>();
            data.NotifyTypes    = new List <DTO.Support.NotifyType>();
            data.PODs           = new List <DTO.Support.POD>();

            //try to get data
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    // add new case
                    if (id > 0)
                    {
                        data.Data = converter.DB2DTO_ShippingInstruction(context.ShippingInstructionMng_ShippingInstruction_View.FirstOrDefault(o => o.ShippingInstructionID == id));
                    }

                    data.Clients        = supportFactory.GetClient().ToList();
                    data.ConsigneeTypes = supportFactory.GetConsigneeTypes().ToList();
                    data.Countries      = supportFactory.GetClientCountry().ToList();
                    data.Forwarders     = supportFactory.GetForwarder().ToList();
                    data.NotifyTypes    = supportFactory.GetNotifyTypes().ToList();
                    data.PODs           = supportFactory.GetPOD().ToList();
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
예제 #4
0
        public override bool DeleteData(int id, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    ShippingInstruction dbItem = context.ShippingInstruction.FirstOrDefault(o => o.ShippingInstructionID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Shipping instruction not found!";
                        return(false);
                    }
                    else
                    {
                        if (dbItem.IsConfirmed.HasValue && dbItem.IsConfirmed.Value)
                        {
                            throw new Exception("The shipping instruction has been confirmed and can not be deleted");
                        }

                        context.ShippingInstruction.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification = new Library.DTO.Notification()
                {
                    Message = ex.Message
                };
                return(false);
            }
        }
예제 #5
0
        public DTO.ShippingInstructionMng.PODCountry GetCountryFromPODfunction(int podid, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ShippingInstructionMng.PODCountry data = new DTO.ShippingInstructionMng.PODCountry();

            //try to get data
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    data = converter.DB2DTO_PODCountry(context.ShippingInstructionMng_PODCountry_View.FirstOrDefault(o => o.PoDID == podid));
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
예제 #6
0
        public DTO.ShippingInstructionMng.ShippingInstruction GetDefault(int clientId, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ShippingInstructionMng.ShippingInstruction data = new DTO.ShippingInstructionMng.ShippingInstruction();

            //try to get data
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    data = converter.DB2DTO_ShippingInstruction(context.ShippingInstructionMng_ShippingInstruction_View.FirstOrDefault(o => o.ClientID == clientId && o.IsDefault.HasValue && o.IsDefault.Value));
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }
예제 #7
0
        public override DTO.ShippingInstructionMng.SearchFormData GetDataWithFilter(System.Collections.Hashtable filters, int pageSize, int pageIndex, string orderBy, string orderDirection, out int totalRows, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            DTO.ShippingInstructionMng.SearchFormData data = new DTO.ShippingInstructionMng.SearchFormData();
            data.Data = new List <DTO.ShippingInstructionMng.ShippingInstructionSearchResult>();
            totalRows = 0;

            //try to get data
            try
            {
                using (ShippingInstructionMngEntities context = CreateContext())
                {
                    string ClientUD          = null;
                    string ProformaInvoiceNo = null;
                    string Priority          = null;
                    int?   PODID             = null;
                    bool?  IsDefault         = null;
                    bool?  IsSample          = null;

                    if (filters.ContainsKey("ClientUD") && !string.IsNullOrEmpty(filters["ClientUD"].ToString()))
                    {
                        ClientUD = filters["ClientUD"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("ProformaInvoiceNo") && !string.IsNullOrEmpty(filters["ProformaInvoiceNo"].ToString()))
                    {
                        ProformaInvoiceNo = filters["ProformaInvoiceNo"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("PODID") && !string.IsNullOrEmpty(filters["PODID"].ToString()))
                    {
                        PODID = (int)filters["PODID"];
                    }
                    if (filters.ContainsKey("Priority") && !string.IsNullOrEmpty(filters["Priority"].ToString()))
                    {
                        Priority = filters["Priority"].ToString().Replace("'", "''");
                    }
                    if (filters.ContainsKey("IsDefault") && !string.IsNullOrEmpty(filters["IsDefault"].ToString()))
                    {
                        if (filters["IsDefault"].ToString() == "1")
                        {
                            IsDefault = true;
                        }
                        else
                        {
                            IsDefault = false;
                        }
                    }
                    if (filters.ContainsKey("IsSample") && !string.IsNullOrEmpty(filters["IsSample"].ToString()))
                    {
                        if (filters["IsSample"].ToString() == "1")
                        {
                            IsSample = true;
                        }
                        else
                        {
                            IsSample = false;
                        }
                    }

                    totalRows = context.ShippingInstructionMng_function_SearchShippingInstruction(ClientUD, PODID, ProformaInvoiceNo, Priority, IsDefault, IsSample, orderBy, orderDirection).Count();
                    var result = context.ShippingInstructionMng_function_SearchShippingInstruction(ClientUD, PODID, ProformaInvoiceNo, Priority, IsDefault, IsSample, orderBy, orderDirection);

                    data.Data = converter.DB2DTO_ShippingInstructionSearchResultList(result.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList());
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
            }

            return(data);
        }