Exemplo n.º 1
0
        public ActionResult DeleteMemberOrderDetail(int productDetailID, int memberOrderID)
        {
            MemberOrder memberOrder = _entities.MemberOrders.Single(a => a.ID == memberOrderID);

            MemberOrderDetail memberOrderDetail = _entities.MemberOrderDetails.Single(a => a.ProductDetailID == productDetailID && a.MemberOrderID == memberOrderID && a.MemberOrder.OrderStatusID == 1);

            decimal realPrice = GetProductPriceAfterDiscount(memberOrderDetail.ProductDetail.Product, memberOrderDetail.Quantity);

            memberOrder.Price -= realPrice;

            //float discount = 0;
            //if (memberOrderDetail.ProductDetail.Product.ProductDiscounts.Any(a => a.DateTo >= DateTime.Today))
            //{
            //    discount = memberOrderDetail.ProductDetail.Product.ProductDiscounts.Where(a => a.DateTo >= DateTime.Today).FirstOrDefault().Discount;
            //}
            //memberOrder.Price -= memberOrderDetail.Quantity * memberOrderDetail.ProductDetail.Product.UnitPrice * (1 - (decimal)discount);

            _entities.DeleteObject(memberOrderDetail);
            _entities.SaveChanges();

            bool exist          = _entities.MemberOrderDetails.Any(a => a.MemberOrderID == memberOrderID);
            int  productOrderID = memberOrder.ProductOrderID;

            if (exist)
            {
                return(RedirectToAction("Details", new { memberOrderID = memberOrderID, orderStatusID = memberOrder.OrderStatusID }));
            }
            else
            {
                _entities.DeleteObject(memberOrder);
                _entities.SaveChanges();
                return(RedirectToAction("ProductList", new { productOrderID = productOrderID }));
            }
        }
Exemplo n.º 2
0
 protected virtual void CloneFrom(ObjectBrowserSettings source)
 {
     m_memberOrder        = source.m_memberOrder;
     m_showMembers        = source.m_showMembers;
     m_showNonPublic      = source.m_showNonPublic;
     m_showTypeCheckBoxes = source.m_showTypeCheckBoxes;
     m_typeOrder          = source.m_typeOrder;
 }
Exemplo n.º 3
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            if (id != 0)
            {
                MemberOrder memberOrder = _entities.MemberOrders.Single(a => a.ID == id);

                _entities.DeleteObject(memberOrder);
                _entities.SaveChanges();
            }
            return(View("Deleted"));
        }
Exemplo n.º 4
0
        private int RemoveMemberOrderDetailsFromMemberOrder(int productID, MemberOrder memberOrder)
        {
            List <MemberOrderDetail> memberOrderDetails = memberOrder.MemberOrderDetails.Where(a => a.ProductDetail.ProductID == productID).ToList();
            int memberOrderDetailCounts = memberOrderDetails.Count;

            foreach (MemberOrderDetail memberOrderDetail in memberOrderDetails)
            {
                //MinusMemberOrderPrice(memberOrder, memberOrderDetail);
                decimal realPrice = GetProductPriceAfterDiscount(memberOrderDetail.ProductDetail.Product, memberOrderDetail.Quantity);
                memberOrder.Price -= realPrice;
                _entities.MemberOrderDetails.DeleteObject(memberOrderDetail);
            }
            return(memberOrderDetailCounts);
        }
Exemplo n.º 5
0
        public void AddToMemberOrderDetailForProduct(FormCollection collection, MemberOrder memberOrder, int productID)
        {
            string[] productQuantitys = collection.Get("Quantity").Split(',');

            int     j          = 0;
            decimal totalPrice = 0;

            List <ProductDetail> productDetails = _entities.ProductDetails.Where(a => a.ProductID == productID && a.UpdateDate > SMCHSGManager.Controllers.ProductController.updateTime).ToList();

            foreach (ProductDetail pd in productDetails)
            {
                if (!string.IsNullOrEmpty(productQuantitys[j]) && IsDigitString(productQuantitys[j]) && int.Parse(productQuantitys[j]) > 0)
                {
                    MemberOrderDetail memberOrderDetail = new MemberOrderDetail();
                    memberOrderDetail.ProductDetail = pd;
                    memberOrderDetail.Quantity      = short.Parse(productQuantitys[j]);
                    memberOrder.MemberOrderDetails.Add(memberOrderDetail);
                    float discount = 0;
                    if (pd.Product.ProductDiscounts.Any(a => a.DateTo >= DateTime.Today))
                    {
                        discount = pd.Product.ProductDiscounts.Where(a => a.DateTo >= DateTime.Today).FirstOrDefault().Discount;
                    }
                    if (discount != 0.3333f)
                    {
                        totalPrice += memberOrderDetail.ProductDetail.Product.UnitPrice * (1 - (decimal)discount) * memberOrderDetail.Quantity;
                    }
                    else
                    {
                        int backNos = memberOrderDetail.Quantity / 3;
                        totalPrice += memberOrderDetail.ProductDetail.Product.UnitPrice * (memberOrderDetail.Quantity - backNos);
                    }
                }
                j++;
            }
            if (totalPrice == 0)
            {
                ModelState.AddModelError("", "please input the quantity of product.");
            }
            else
            {
                memberOrder.Price       += totalPrice;
                memberOrder.CurrencyCode = memberOrder.MemberOrderDetails.FirstOrDefault().ProductDetail.Product.CurrencyCode;
            }
        }
Exemplo n.º 6
0
        public ActionResult Delete(int id)
        {
            MemberOrder memberOrder = _entities.MemberOrders.Single(a => a.ID == id);

            return(View(memberOrder));
        }
Exemplo n.º 7
0
        public ActionResult AddToOrderBag(FormCollection collection, int productID, int productOrderID, int?page, Guid?memberID)
        {
            if (!memberID.HasValue)
            {
                memberID = (Guid)Membership.GetUser().ProviderUserKey;
            }
            MemberOrder memberOrder = new MemberOrder();

            if (_entities.MemberOrders.Where(a => a.ProductOrderID == productOrderID && a.MemberID == memberID.Value && a.OrderStatusID == 1).Any())
            {
                memberOrder = _entities.MemberOrders.Single(a => a.ProductOrderID == productOrderID && a.MemberID == memberID.Value && a.OrderStatusID == 1);
            }
            else
            {
                memberOrder.MemberID       = memberID.Value;
                memberOrder.ProductOrderID = productOrderID;
                memberOrder.OrderStatusID  = 1;
            }
            memberOrder.LatestOrderDateTime = DateTime.Now.ToUniversalTime().AddHours(8);

            try
            {
                int memberOrderDetailCounts = RemoveMemberOrderDetailsFromMemberOrder(productID, memberOrder);
                AddToMemberOrderDetailForProduct(collection, memberOrder, productID);
                _entities.SaveChanges();

                if (!ModelState.IsValid)
                {
                    if (memberOrderDetailCounts > 0 && memberOrder.MemberOrderDetails.Count == 0)
                    {
                        _entities.DeleteObject(memberOrder);
                        _entities.SaveChanges();
                        return(RedirectToAction("ProductList", new { productOrderID = productOrderID, page = page }));
                    }
                    else if (memberOrderDetailCounts > 0)
                    {
                        return(RedirectToAction("Details", new { memberOrderID = memberOrder.ID, orderStatusID = memberOrder.OrderStatusID, page = page }));
                    }
                    throw new Exception();
                }

                if (memberOrder.ID == 0)
                {
                    _entities.AddToMemberOrders(memberOrder);
                    memberOrder = (from r in _entities.MemberOrders where r.ProductOrderID == productOrderID select r).OrderByDescending(x => x.ID).First();
                }
                else
                {
                    UpdateModel(memberOrder, "MemberOrder");
                }
                _entities.SaveChanges();

                return(RedirectToAction("Details", new { memberOrderID = memberOrder.ID, orderStatusID = memberOrder.OrderStatusID, page = page }));
            }
            catch
            {
                List <ProductDetail> productDetails = _entities.ProductDetails.Where(a => a.ProductID == productID && a.UpdateDate > SMCHSGManager.Controllers.ProductController.updateTime && (a.UnitsInStock == null || a.UnitsInStock != null && a.UnitsInStock > 0)).OrderBy(a => a.ID).ToList();

                List <string> productQuantities = GetProductDetailQuantities(productID, productOrderID, memberID.Value, productDetails);
                ViewData["productQuantities"] = productQuantities.ToArray();

                var viewModel = new ProductDetailViewModel
                {
                    Sizes   = productDetails.Select(a => a.SizeDescription).ToList(),
                    Product = _entities.Products.Single(a => a.ID == productID),
                };
                viewModel.ProductDiscount = viewModel.Product.ProductDiscounts.Where(a => a.DateTo >= DateTime.Today).FirstOrDefault();
                viewModel.ReadPrice       = GetProductPriceAfterDiscount(viewModel.Product, 1);

                if (viewModel.Product.ProductUploadFiles.Count == 0)
                {
                    UploadFile        upload            = _entities.UploadFiles.Single(a => a.ID == 1276);
                    ProductUploadFile productUploadFile = new ProductUploadFile();
                    productUploadFile.UploadFile = upload;
                    viewModel.Product.ProductUploadFiles.Add(productUploadFile);
                }

                return(View(viewModel));
            }
        }
Exemplo n.º 8
0
        public string AddOrderTemp(RequestOrderInfo orderInfo)
        {
            try
            {
                #region  单判断库存部分
                if (orderInfo.OrderType != 2)
                {
                    foreach (var item in orderInfo.OrderDetaile)
                    {
                        var sql = string.Format("Select Stock from SKU Where SkuId = {0}", item.SkuId);
                        var q   = dataContext.ExecuteScalar(CommandType.Text, sql);

                        if ((int)q < item.Count)
                        {
                            return("Stock is not enough");
                        }
                    }
                }
                #endregion

                //操作订单积分
                string integralSql = string.Format("update RegistMember Set LeaveIntegral = LeaveIntegral - {0} where MemberId = {1}", orderInfo.OrderPrice, orderInfo.MemberId);
                int    nums        = dataContext.ExecuteNonQuery(CommandType.Text, integralSql);

                if (nums > 0)
                {
                    #region 订单新增部分
                    MemberOrder order = new MemberOrder();
                    order.MemberId       = orderInfo.MemberId;
                    order.OrderName      = orderInfo.OrderName;
                    order.OrderTelephone = orderInfo.OrderTelephone;
                    order.OrderState     = orderInfo.OrderState;
                    order.OrderAddress   = orderInfo.OrderAddress;
                    order.OrderPrice     = orderInfo.OrderPrice;
                    order.OrderType      = orderInfo.OrderType;
                    order.InventedType   = orderInfo.InventedType;
                    order.LogisticsNo    = "";
                    order.LogisticsType  = "";
                    order.OrderFrom      = orderInfo.OrderFrom;
                    order.OrderRemark    = orderInfo.OrderRemark;
                    order.AddDate        = DateTime.Now;

                    db.Order.Add(order);
                    db.SaveChanges();
                    #endregion

                    string date   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    string remark = "积分商城:" + order.OrderId;
                    //记录积分操作日志
                    string logsql = string.Format("insert into MemberIntegralDetail values({0},{1},'{2}',2,'积分商城','{2}','{3}','','');", order.MemberId, order.OrderPrice, date, remark);
                    dataContext.ExecuteNonQuery(CommandType.Text, logsql);

                    #region 新增订单商品
                    //新增完订单获取到订单ID然后录入订单商品
                    foreach (var item in orderInfo.OrderDetaile)
                    {
                        string sql = string.Format("Insert into OrderDetaile Values({0},{1},'{2}',{3},{4})", order.OrderId, item.SkuId, item.SkuName, item.ProductId, item.Count);

                        var count = dataContext.ExecuteNonQuery(CommandType.Text, sql);

                        string stockSql = string.Format("Update SKU Set Stock = Stock - {0} Where SkuId = {1}", item.Count, item.SkuId);
                        dataContext.ExecuteNonQuery(CommandType.Text, stockSql);
                    }
                    #endregion

                    //虚拟商品订单-欧飞充值
                    //if (order.OrderType == 2)
                    //{
                    //    int id = orderInfo.OrderDetaile[0].SkuId;
                    //    int skuNum = orderInfo.OrderDetaile[0].Count;
                    //    SKU sku = (from s in db.SKU
                    //               where s.SkuId == id
                    //               select s).FirstOrDefault();
                    //    int price = Convert.ToInt32(sku.MarketPrice);

                    //    if (!string.IsNullOrEmpty(order.OrderTelephone))
                    //    {
                    //        for (int i = 0; i < skuNum; i++)
                    //        {
                    //            LogHelper.WriteLog("共" + skuNum + "件商品,充值电话:" + order.OrderTelephone + ",充值的面值:" + price);
                    //            InventedManage(order.InventedType, order.OrderTelephone, i.ToString(), order.OrderId.ToString(), price);
                    //        }
                    //    }
                    //}
                    return("succ");
                }
                else
                {
                    Common.LogHelper.WriteLog("CreateOrderFromTemp-AddOrder-error" + orderInfo.MemberId.ToString() + orderInfo.OrderName + "Integral is not enough");
                    return("Integral is not enough");
                }
            }
            catch (Exception ex)
            {
                Common.LogHelper.WriteLog("CreateOrderFromTemp-AddOrder-error" + orderInfo.MemberId.ToString() + ex.ToString());
                return("error");
            }
        }