Exemplo n.º 1
0
        public async Task <IActionResult> CheckOut(Order anorder)
        {
            List <Product> products = HttpContext.Session.Get <List <Product> >("products");

            if (products != null)
            {
                foreach (var product in products)
                {
                    OrderDetaile orderDetails = new OrderDetaile();
                    orderDetails.ProductId = product.Id;

                    anorder.OrderDetailes.Add(orderDetails);
                }
                anorder.OrderNo = GetOrderNo();
                _context.Orders.Add(anorder);
                await _context.SaveChangesAsync();

                HttpContext.Session.Set("products", new List <Product>());
                return(RedirectToAction("Remerci"));
            }
            else
            {
                return(View());
            }
            // return RedirectToAction(nameof(HomeController.Index), "Home");
        }
Exemplo n.º 2
0
        public string CreateOrderFromTemp()
        {
            string    sql = string.Format(@"SELECT  a.Id,a.OpenId ,a.Name,a.Phone,a.PrizeName,c.MemberId,s.SkuId,s.Price,
                                        u.Province+u.City+u.Area+u.Address Address,p.ProductType ,p.ProductId
                                        FROM dbo.TempOrder a 
                                        JOIN dbo.TempUsers u ON u.OpenId = a.OpenId
                                        JOIN dbo.OpenIdAssociated b ON b.OpenId = a.OpenId AND b.UserType =2
                                        JOIN dbo.RegistMember c ON c.MemberId = b.UserId 
                                        JOIN dbo.SKU s ON a.PrizeName = s.SkuName
                                        JOIN dbo.Product p ON p.ProductId = s.ProductId
                                        WHERE (a.Status IS NULL  or LEN(a.Status) =0 ) 
                                            AND a.CreateDate >'2018-09-26 17:50:39.040'  
                                            AND (u.City IS NOT NULL AND LEN(u.City)>0) order by  Id");
            DataTable dt  = dataContext.ExecuteDataTable(CommandType.Text, sql);

            RequestOrderInfo    or           = new RequestOrderInfo();
            List <OrderDetaile> orDetailList = new List <OrderDetaile>();
            OrderDetaile        orDetail     = new OrderDetaile();

            foreach (DataRow dr in dt.Rows)
            {
                or           = new RequestOrderInfo();
                orDetailList = new List <OrderDetaile>();
                orDetail     = new OrderDetaile();
                try
                {
                    if (string.IsNullOrEmpty(dr["Phone"].ToString()))
                    {
                        sql = string.Format(@"UPDATE dbo.TempOrder SET Status = 'fail',Remark='手机号为空' WHERE Id = {0}", dr["Id"].ToString());
                        dataContext.ExecuteNonQuery(CommandType.Text, sql);
                    }
                    else
                    {
                        //orderitem
                        orDetail.OrderDetaileId = 0;
                        orDetail.OrderId        = 0;
                        orDetail.SkuId          = Convert.ToInt32(dr["SkuId"]);
                        orDetail.SkuName        = dr["PrizeName"].ToString();
                        orDetail.ProductId      = Convert.ToInt32(dr["ProductId"]);
                        orDetail.Count          = 1;
                        orDetailList.Add(orDetail);

                        //order基本信息
                        or.MemberId       = Convert.ToInt32(dr["MemberId"]);
                        or.OrderName      = dr["Name"].ToString();
                        or.OrderTelephone = dr["Phone"].ToString();
                        or.OrderState     = "备货中";
                        or.OrderAddress   = dr["Address"].ToString();
                        or.OrderPrice     = 0;//Convert.ToInt32(dr["Price"]);
                        or.OrderType      = Convert.ToInt32(dr["ProductType"]);
                        or.InventedType   = Convert.ToInt32(dr["ProductType"]) == 1 ? 0 : 1;
                        or.OrderFrom      = "匠心寻百味抽奖";
                        or.OrderRemark    = "";

                        or.OrderDetaile = orDetailList;

                        if (AddOrderTemp(or) == "succ")
                        {
                            sql = string.Format("UPDATE TempOrder SET Status = 'succ' WHERE Id = {0}", dr["Id"].ToString());
                            dataContext.ExecuteNonQuery(CommandType.Text, sql);
                        }
                    }
                }
                catch (Exception ex)
                {
                    sql = string.Format("UPDATE TempOrder SET Status = 'fail',Remark='{1}' WHERE Id = {0}", dr["Id"].ToString(), ex.ToString());
                    dataContext.ExecuteNonQuery(CommandType.Text, sql);
                    Common.LogHelper.WriteLog("CreateOrderFromTemp-error" + Convert.ToInt32(dr["OpenId"]) + ex.ToString());
                }
            }
            return("");
        }