Ejemplo n.º 1
0
        public void Add(Order order)
        {
            owner = GetOwner();
            vendor = GetVendor(order.VendorID);

            using (cn = dbContext.Database.Connection)
            {
                try
                {
                    cn.Open();
                    tran = cn.BeginTransaction();
                    DbCommand cmd = cn.CreateCommand();
                    cmd.Transaction = tran;
                    cmd.CommandText = @"INSERT INTO tblSO (SOCode, SODate, BranchId, CurrencyId, EmployeeId, VendorID, TermID, TaxID, SOGrossAmt, SONetAmt, StatusID, Operator, Computer, LastUpdate)
                      VALUES (@SOCode, @SODate, @BranchId, @CurrencyId, @EmployeeId, @VendorId, @TermId, 0, @SOGrossAmt, @SONetAmt, 0, @Operator, @Computer, @LastUpdate); SELECT IDENT_CURRENT('tblSO');";

                    cmd.Parameters.Add(new SqlParameter("@SOCode", order.SOCode));
                    cmd.Parameters.Add(new SqlParameter("@SODate", order.SODate));
                    cmd.Parameters.Add(new SqlParameter("@BranchId", order.BranchID));
                    cmd.Parameters.Add(new SqlParameter("@CurrencyId", order.CurrencyId));
                    cmd.Parameters.Add(new SqlParameter("@EmployeeId", owner.EmployeeId));
                    cmd.Parameters.Add(new SqlParameter("@VendorId", vendor.Id));
                    cmd.Parameters.Add(new SqlParameter("@TermId", owner.DefTerm));
                    cmd.Parameters.Add(new SqlParameter("@SOGrossAmt", order.SOGrossAmt));
                    cmd.Parameters.Add(new SqlParameter("@SONetAmt", order.SONetAmt));
                    cmd.Parameters.Add(new SqlParameter("@Operator", order.Username));
                    cmd.Parameters.Add(new SqlParameter("@Computer", System.Environment.MachineName));
                    cmd.Parameters.Add(new SqlParameter("@LastUpdate", DateTime.Now));

                    soId = Convert.ToInt32(cmd.ExecuteScalar());

                    foreach (OrderItem item in order.Items)
                    {
                        AddOrderItem(item);
                    }

                    tran.Commit();
                }
                catch (Exception ex)
                {
                    if (tran != null)
                        tran.Rollback();

                    throw ex;
                }
                finally
                {
                    cn.Close();
                }
            }
        }
Ejemplo n.º 2
0
        public JsonResult Checkout()
        {
            return CatchPosibleExeption(() =>
            {
                orderNumber = this.orderUow.ShoppingCarts.GetOrderNumber(OrderSession.Branch.BranchCode);
                orderNumber.Next();
                this.orderUow.ShoppingCarts.SaveOrderNumber(orderNumber);

                using (var porderServiceChannel = OrderSession.OrderServiceChannelFactory.CreateChannel())
                {
                    ShoppingCart sc = this.orderUow.ShoppingCarts.Get(this.User.Identity.Name);
                    if (sc == null)
                        throw new ApplicationException("Shopping cart not found");

                    ShoppingCartSnapshot snapshot = sc.CreateSnapshot();
                    List<porder.model.OrderItem> porderItems = new List<porder.model.OrderItem>();
                    int orderItemSequence = 0;
                    foreach (ShoppingCartItemSnapshot itemSnapshot in snapshot.Items)
                    {
                        porderItems.Add(new porder.model.OrderItem
                        {
                            SOSeq = ++orderItemSequence,
                            ItemID = itemSnapshot.ItemId,
                            UnitCode = itemSnapshot.UnitCode,
                            Price = itemSnapshot.Price,
                            Quantity = itemSnapshot.Qty,
                            GrossAmt = itemSnapshot.AmountAfterDiscount,
                            SubTotal = itemSnapshot.AmountAfterDiscount
                        });
                    }
                    po = new porder.model.Order
                    {
                        Items = porderItems,
                        BranchID = OrderSession.Branch.BranchCode,
                        SOCode = orderNumber.OrderNumberString(),
                        CurrencyId = "IDR",
                        SODate = DateTime.Today,
                        Username = this.User.Identity.Name,
                        VendorID = this.OrderSession.Branch.BranchCode,
                        SOGrossAmt = snapshot.TotalAmountAfterDiscount,
                        SONetAmt = snapshot.TotalAmountAfterDiscount
                    };
                    porder.model.CreateOrderResponse response = porderServiceChannel.CreateOrder(po);
                    if (response.Error)
                        throw new ApplicationException(response.ErrorMessage);
                };

                order.model.ShoppingCart.CheckoutCommand cmd = new ShoppingCart.CheckoutCommand
                {
                    BranchId = OrderSession.Branch.Id,
                    OrderDate = po.SODate,
                    OrderNumber = this.orderNumber.OrderNumberString(),
                    BranchCode = OrderSession.Branch.BranchCode,
                    Username = this.User.Identity.Name
                };

                var explicitArgs = new StructureMap.Pipeline.ExplicitArguments();
                explicitArgs.SetArg("orderUow", this.orderUow);

                order.service.contract.IOrderService orderService = ObjectFactory.GetInstance<order.service.contract.IOrderService>(explicitArgs);
                orderService.CheckoutOut(cmd, () => { this.orderUow.ShoppingCarts.SaveOrderNumber(orderNumber); });

                return Json(new { success = true });
            });
        }