public ServiceResult AddOrderOrderDetail(OrderOrderDetailDTO orders)
        {
            _uow.BeginTran();

            Order newOrder = new Order()
            {
                CustomerID = orders.CustomerID,
                Adress     = orders.Adress,
                OrderDate  = orders.OrderDate,
                SubTotal   = orders.SelectedOrders.Sum(x => x.TotalAmount)
            };

            _or.Add(newOrder);
            try
            {
                foreach (var item in orders.SelectedOrders)
                {
                    item.OrderID = newOrder.ID;
                    var orderDetail = Helper.Helpers.Mapping <OrderDetailDTO, OrderDetail>(item);
                    _odr.Add(orderDetail);
                }

                _uow.CommitTran();
                return(new ServiceResult(ProcessStateEnum.Success, "Kayıt başarıyla yapılmıştır."));
            }
            catch (Exception)
            {
                _uow.RollBackTran();
                return(new ServiceResult(ProcessStateEnum.Error, "Bir hata nedeniyle kayıt yapılamamıştır."));
            }
            finally
            {
                _uow.Dispose();
            }
        }
Exemple #2
0
        public ActionResult PlaceOrder(OrderDTO model)
        {
            var orderDetails = (List <OrderDetailDTO>)Session["cartDetails"];

            var customerID = model.CustomerID;
            var adress     = model.Adress;

            var orderOrderDetailDto = new OrderOrderDetailDTO()
            {
                CustomerID     = customerID,
                Adress         = adress,
                OrderDate      = DateTime.Now,
                SelectedOrders = orderDetails
            };

            _oods.AddOrderOrderDetail(orderOrderDetailDto);



            //alttakine benzer bi kod bloğu olacak sipariş bilgilerini aldıktan sonra
            //id leri transaction ile ayarlamamız gerekiyor bi hata olursa o siparişi oluşturmasın db de diye

            //ShippingDetail shpDetails = new ShippingDetail();
            //shpDetails.ShippingID = shpID;
            //shpDetails.FirstName = getCheckoutDetails["FirstName"];
            //shpDetails.LastName = getCheckoutDetails["LastName"];
            //shpDetails.Email = getCheckoutDetails["Email"];
            //shpDetails.Mobile = getCheckoutDetails["Mobile"];
            //shpDetails.Address = getCheckoutDetails["Address"];
            //shpDetails.Province = getCheckoutDetails["Province"];
            //shpDetails.City = getCheckoutDetails["City"];
            //shpDetails.PostCode = getCheckoutDetails["PostCode"];
            //db.ShippingDetails.Add(shpDetails);
            //db.SaveChanges();

            //Payment pay = new Payment();
            //pay.PaymentID = payID;
            //pay.Type = Convert.ToInt32(getCheckoutDetails["PayMethod"]);
            //db.Payments.Add(pay);
            //db.SaveChanges();

            //Order o = new Order();
            //o.OrderID = orderID;
            //o.CustomerID = TempShpData.UserID;
            //o.PaymentID = payID;
            //o.ShippingID = shpID;
            //o.Discount = Convert.ToInt32(getCheckoutDetails["discount"]);
            //o.TotalAmount = Convert.ToInt32(getCheckoutDetails["totalAmount"]);
            //o.isCompleted = true;
            //o.OrderDate = DateTime.Now;
            //db.Orders.Add(o);
            //db.SaveChanges();

            //foreach (var OD in TempShpData.items)
            //{
            //    OD.OrderID = orderID;
            //    OD.Order = db.Orders.Find(orderID);
            //    OD.Product = db.Products.Find(OD.ProductID);
            //    db.OrderDetails.Add(OD);
            //    db.SaveChanges();
            //}


            //return RedirectToAction("Index", "ThankYou");



            //_uow.BeginTran();
            //try
            //{
            //    Customer newCustomer = new Customer();
            //    newCustomer.UserID = newUser.ID;
            //    newCustomer.FirstName = customeruser.FirstName;
            //    newCustomer.LastName = customeruser.LastName;
            //    newCustomer.Email = customeruser.eMail;
            //    _cr.Add(newCustomer);

            //    _uow.CommitTran();
            //    return new ServiceResult(ProcessStateEnum.Success, "Kayıt başarıyla yapılmıştır.");
            //}
            //catch (Exception)
            //{
            //    _uow.RollBackTran();
            //    return new ServiceResult(ProcessStateEnum.Error, "Bir hata nedeniyle kayıt yapılamamıştır.");
            //}

            return(RedirectToAction("Confirmation", "CheckOut"));
        }