Exemplo n.º 1
0
        public ActionResult Direct(int id, int group, string action)
        {
            ServiceClient sc = Sas.GetAuthenticatedServiceClient(this, action);
            var nodes = BuildPaymentGraph( sc,  group,  id);
            var WindowInfo = sc.GetTransactionWindow(id, group);
            Models.PaymentData pd = new Models.PaymentData() { Title = WindowInfo.Name + " Direct Payment" };
            pd.Lines = new List<Models.PaymentLine>();
            var users = sc.GetAllUsersInGroup(group);

            foreach (var node in nodes)
            {
                foreach (var edge in node.EdgeWeight)
                {
                    if (edge.Value > 0)
                    {
                        Models.PaymentLine pl = new Models.PaymentLine();
                        pl.FromUsername = users.Where(p => p.Id == node.UserId).SingleOrDefault().Username;
                        pl.ToUsername = users.Where(p => p.Id == edge.Key).SingleOrDefault().Username;
                        pl.Amount = edge.Value;
                        pd.Lines.Add(pl);
                    }
                }
            }

            return View(pd);
        }
        private Models.PaymentData CreatePayment(NewOrderViewModel data)
        {
            var paymentModel = new Models.PaymentData
            {
                Amount        = data.TotalAmount,
                Date          = DateTime.Now,
                LastDigitCard = data.PaymentData.Card.Substring(data.PaymentData.Card.Length - 5, 4)
            };

            UnitOfWork.Set <Models.PaymentData>().Add(paymentModel);
            UnitOfWork.SaveChanges();
            return(paymentModel);
        }
        public int Save(NewOrderViewModel data)
        {
            User user = UnitOfWork.User.Where(p => p.Email == data.User.Email).FirstOrDefault();

            if (user == null || !user.Active)
            {
                return(-1);
            }

            Models.PaymentData paymentModel = CreatePayment(data);

            var orderModel = new Order
            {
                CreationDate  = DateTime.Now,
                TotalAmount   = data.TotalAmount,
                FkUser        = user.IdUser,
                FkPaymentData = paymentModel.IdPaymentData,
                Active        = true
            };

            UnitOfWork.Set <Order>().Add(orderModel);
            UnitOfWork.SaveChanges();

            foreach (var item in data.ProductsID)
            {
                Product productTemp = UnitOfWork.Product.Find(item);
                if (productTemp != null)
                {
                    var productByOrder = new ProductByOrder
                    {
                        FkProduct = productTemp.IdProduct,
                        FkOrder   = orderModel.IdOrder
                    };

                    UnitOfWork.Set <ProductByOrder>().Add(productByOrder);
                    UnitOfWork.SaveChanges();
                }
            }
            return(orderModel.IdOrder);
        }