Ejemplo 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 (TransportationFeeEntities context = CreateContext())
                {
                    SaleOrder dbItem = context.SaleOrders.FirstOrDefault(o => o.SaleOrderID == id);
                    if (dbItem == null)
                    {
                        notification.Message = "Sale Order not found!";
                        return(false);
                    }
                    else
                    {
                        context.SaleOrders.Remove(dbItem);
                        context.SaveChanges();

                        return(true);
                    }
                }
            }
            catch (Exception ex)
            {
                notification.Type    = Library.DTO.NotificationType.Error;
                notification.Message = ex.Message;
                return(false);
            }
        }
Ejemplo n.º 2
0
        public override bool UpdateData(int id, ref DTO.TransportationFeeMng.TransportationFee dtoItem, out Library.DTO.Notification notification)
        {
            notification = new Library.DTO.Notification()
            {
                Type = Library.DTO.NotificationType.Success
            };
            int    number;
            string indexName;

            try
            {
                using (TransportationFeeEntities context = CreateContext())
                {
                    SaleOrder dbItem = null;
                    if (id == 0)
                    {
                        dbItem = new SaleOrder();
                        context.SaleOrders.Add(dbItem);
                    }
                    else
                    {
                        dbItem = context.SaleOrders.FirstOrDefault(o => o.SaleOrderID == id);
                    }

                    if (dbItem == null)
                    {
                        notification.Message = "Sale order not found!";
                        return(false);
                    }
                    else
                    {
                        converter.DTO2BD_TransportationFee(dtoItem, ref dbItem);
                        context.SaveChanges();

                        dtoItem = GetData(dbItem.SaleOrderID, out notification).Data;

                        return(true);
                    }
                }
            }
            catch (System.Data.DataException dEx)
            {
                notification.Type = Library.DTO.NotificationType.Error;
                Library.ErrorHelper.DataExceptionParser(dEx, out number, out indexName);
                if (number == 2601 && !string.IsNullOrEmpty(indexName))
                {
                    if (indexName == "SaleOrderIDUnique")
                    {
                        notification.Message = "Sale order already exists!";
                    }
                }
                else
                {
                    notification.Message = dEx.Message;
                }

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