Exemple #1
0
        public int SaveOrderDetail(HsrOrderApp.BL.DomainModel.OrderDetail detail, HsrOrderApp.BL.DomainModel.Order forThisOrder)
        {
            try
            {
                string      setname = "OrderDetailSet";
                OrderDetail dbOrderDetail;
                bool        isNew = false;
                if (detail.OrderDetailId == default(int) || detail.OrderDetailId <= 0)
                {
                    isNew         = true;
                    dbOrderDetail = new OrderDetail();
                }
                else
                {
                    dbOrderDetail = new OrderDetail()
                    {
                        OrderDetailId = detail.OrderDetailId, Version = detail.Version.ToTimestamp()
                    };
                    dbOrderDetail.EntityKey = db.CreateEntityKey(setname, dbOrderDetail);
                    db.AttachTo(setname, dbOrderDetail);
                }
                dbOrderDetail.UnitPrice       = detail.UnitPrice;
                dbOrderDetail.QuantityInUnits = detail.QuantityInUnits;


                if (isNew)
                {
                    dbOrderDetail.OrderReference.EntityKey   = new EntityKey("HsrOrderAppEntities.OrderSet", "OrderId", detail.Order.OrderId);
                    dbOrderDetail.ProductReference.EntityKey = new EntityKey("HsrOrderAppEntities.ProductSet", "ProductId", detail.Product.ProductId);
                    db.AddToOrderDetailSet(dbOrderDetail);
                }
                else
                {
                    if (dbOrderDetail.ProductReference.GetEnsureLoadedReference().Value.ProductId != detail.Product.ProductId)
                    {
                        Product newProduct = new Product {
                            ProductId = detail.Product.ProductId
                        };
                        db.AttachTo("ProductSet", newProduct);
                        dbOrderDetail.Product = newProduct;
                    }
                }
                db.SaveChanges();

                detail.OrderDetailId = dbOrderDetail.OrderDetailId;
                return(dbOrderDetail.OrderDetailId);
            }
            catch (OptimisticConcurrencyException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
Exemple #2
0
        public int SaveOrder(HsrOrderApp.BL.DomainModel.Order order, bool detached)
        {
            try
            {
                CustomerRepository cr      = new CustomerRepository(this.db);
                string             setname = "OrderSet";

                bool  isNew = false;
                Order dbOrder;
                if (detached == false)
                {
                    dbOrder = db.OrderSet.FirstOrDefault(o => o.OrderId == order.OrderId);
                }
                else if (order.OrderId == default(int) || order.OrderId <= 0)
                {
                    isNew   = true;
                    dbOrder = new Order();
                }
                else
                {
                    dbOrder = new Order()
                    {
                        OrderId = order.OrderId,
                        Version = order.Version.ToTimestamp(),
                    };
                    dbOrder.EntityKey = db.CreateEntityKey(setname, dbOrder);
                    db.AttachTo(setname, dbOrder);
                }
                dbOrder.OrderStatus = (int)order.OrderStatus;
                dbOrder.OrderDate   = order.OrderDate;
                dbOrder.ShippedDate = order.ShippedDate;

                if (isNew)
                {
                    dbOrder.CustomerReference.EntityKey = new EntityKey("HsrOrderAppEntities.CustomerSet", "CustomerId", order.Customer.CustomerId);
                    db.AddToOrderSet(dbOrder);
                }
                else
                {
                    dbOrder.CustomerReference.Attach(db.CustomerSet.First(c => c.CustomerId == order.Customer.CustomerId));
                }
                db.SaveChanges();
                order.OrderId = dbOrder.OrderId;
                return(dbOrder.OrderId);
            }
            catch (OptimisticConcurrencyException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
Exemple #3
0
        public int SaveOrder(HsrOrderApp.BL.DomainModel.Order order, bool detached)
        {
            try
            {
                Order dbOrder = new Order();
                if (detached == false)
                {
                    dbOrder = db.Orders.First(o => o.OrderId == order.OrderId);
                }
                bool isNew = false;
                if (order.OrderId == default(int) || order.OrderId <= 0)
                {
                    isNew = true;
                }

                dbOrder.OrderId     = order.OrderId;
                dbOrder.Version     = order.Version.ToTimestamp();
                dbOrder.OrderStatus = (int)order.OrderStatus;
                dbOrder.OrderDate   = order.OrderDate;
                dbOrder.ShippedDate = order.ShippedDate;
                dbOrder.CustomerId  = order.Customer.CustomerId;

                if (isNew)
                {
                    db.Orders.InsertOnSubmit(dbOrder);
                }
                else if (detached)
                {
                    db.Orders.Attach(dbOrder, true);
                }

                db.SubmitChanges();
                order.OrderId = dbOrder.OrderId;
                return(dbOrder.OrderId);
            }
            catch (ChangeConflictException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
Exemple #4
0
        public int SaveOrderDetail(HsrOrderApp.BL.DomainModel.OrderDetail detail, HsrOrderApp.BL.DomainModel.Order forThisOrder)
        {
            try
            {
                OrderDetail dbOrderDetail = new OrderDetail();
                bool        isNew         = false;
                if (detail.OrderDetailId == default(int) || detail.OrderDetailId <= 0)
                {
                    isNew = true;
                }

                dbOrderDetail.OrderDetailId   = detail.OrderDetailId;
                dbOrderDetail.Version         = detail.Version.ToTimestamp();
                dbOrderDetail.UnitPrice       = detail.UnitPrice;
                dbOrderDetail.QuantityInUnits = detail.QuantityInUnits;
                dbOrderDetail.ProductId       = detail.Product.ProductId;
                dbOrderDetail.OrderId         = forThisOrder.OrderId;

                if (isNew)
                {
                    db.OrderDetails.InsertOnSubmit(dbOrderDetail);
                }
                else
                {
                    db.OrderDetails.Attach(dbOrderDetail, true);
                }
                db.SubmitChanges();
                detail.OrderDetailId = dbOrderDetail.OrderDetailId;
                return(dbOrderDetail.OrderDetailId);
            }
            catch (ChangeConflictException ex)
            {
                if (ExceptionPolicy.HandleException(ex, "DA Policy"))
                {
                    throw;
                }
                return(default(int));
            }
        }
Exemple #5
0
 public int SaveOrder(HsrOrderApp.BL.DomainModel.Order order)
 {
     return(SaveOrder(order, true));
 }