예제 #1
0
        //添加商品,产品上架
        public MessageResult AddProduct(Product product)
        {
            //todo 验证

            _productService.Add(product);
            return(MessageResult.CreateSuccessResult("添加成功", product));
        }
        public MessageResult GetAccountInfo(string loginName)
        {
            var user = _accountService.SingleOrDefault(x => x.LoginName == loginName);

            if (user == null)
            {
                return(MessageResult.CreateFailResult("用户不存在"));
            }
            return(MessageResult.CreateSuccessResult(data: user));
        }
예제 #3
0
        //移除商品
        public MessageResult RemoveProduct(Guid productId)
        {
            var product = _productService.SingleOrDefault(x => x.Id == productId);

            if (product == null)
            {
                return(MessageResult.CreateFailResult("未找到该商品"));
            }
            _productService.Remove(product);
            return(MessageResult.CreateSuccessResult("产品下架成功"));
        }
예제 #4
0
 public MessageResult CreateOrder(Order order)
 {
     if (order.OrderProducts == null || order.OrderProducts.Count == 0)
     {
         return(MessageResult.CreateFailResult("结算失败!"));
     }
     order.Id         = Guid.NewGuid();
     order.CreateTime = DateTime.Now;
     _orderService.Add(order);
     return(MessageResult.CreateSuccessResult());
 }
        public MessageResult LoginIn(string loginName, string password, bool rememberMe = false)
        {
            var account = _accountService.SingleOrDefault(x => x.LoginName == loginName && x.Password == password);

            if (account == null)
            {
                return(MessageResult.CreateFailResult("用户名或者密码不正确"));
            }
            //查询通过,加入缓存 todo...
            FormsAuthentication.SetAuthCookie(loginName, true);
            return(MessageResult.CreateSuccessResult("登录成功", account));
        }
예제 #6
0
        public MessageResult Save(DemoVo demoVo)
        {
            //TL;DR: Add the [FromBody] attribute to the parameter in your ASP.NET Core controller action Note,
            //if you're using ASP.NET Core 2.1, you can also use the [ApiController] attribute
            //to automatically infer the [FromBody] binding source for your complex action method parameters.

            //desc => https://andrewlock.net/model-binding-json-posts-in-asp-net-core/
            //Using the same HTTP requests as previously, we see the following console output,
            //where the x-www-url-formencoded POST is bound correctly,
            //but the JSON POST is not.
            return(MessageResult.CreateSuccessResult("SaveOK", demoVo));
        }
 public MessageResult LoginIn(string loginName, string password)
 {
     //string cookieValue = "";
     //HttpCookie cookieGet = HttpContext.Current.Request.Cookies["userName"];
     //HttpCookie cookieSet = new HttpCookie("username")
     //{
     //    Value = HttpUtility.UrlDecode(loginName, Encoding.GetEncoding("GB2312")),
     //    Expires = DateTime.Now.AddMinutes(10)
     //};
     //HttpContext.Current.Response.Cookies.Add(cookieSet);
     FormsAuthentication.SetAuthCookie(loginName, true);
     return(MessageResult.CreateSuccessResult("登录成功", new { loginName, password }));
 }
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <returns></returns>
        public MessageResult EditPassword(string loginName, string newPwd)
        {
            var account = _accountService.SingleOrDefault(x => x.LoginName == loginName);

            if (account == null)
            {
                return(MessageResult.CreateFailResult("用户名不正确"));
            }
            if (string.IsNullOrEmpty(newPwd))
            {
                return(MessageResult.CreateFailResult("密码不能为空"));
            }
            account.Password = newPwd;
            return(MessageResult.CreateSuccessResult());
        }
        public MessageResult RegisterAccount(RegisterAccount registerAccount)
        {
            //验证:用户正确性、存在性
            if (_accountService.Any(x => x.LoginName == registerAccount.LoginName))
            {
                return(MessageResult.CreateFailResult("用户名不能重复"));
            }
            var account = new Account
            {
                LoginName = registerAccount.LoginName,
                Password  = registerAccount.Password,
                NickName  = registerAccount.NickName
            };

            _accountService.Add(account);
            return(MessageResult.CreateSuccessResult());
        }
예제 #10
0
        public MessageResult AddToCart(string loginName, Guid productId, int count = 1)
        {
            var product    = _productService.Single(x => x.Id == productId);
            var cartEntity = _cartProductService.SingleOrDefault(x => x.loginName == loginName);

            if (cartEntity == null)
            {
                var cart = new Cart()
                {
                    loginName = loginName
                };
                cart.Products.Add(new CartProduct()
                {
                    Product = product,
                    Count   = count
                });
                _cartProductService.Add(cart);
            }
            else
            {
                var cartProduct = cartEntity.Products.SingleOrDefault(x => x.Id == productId);
                if (cartProduct == null)
                {
                    cartEntity.Products.Add(new CartProduct()
                    {
                        Product = product,
                        Count   = count
                    });
                }
                else
                {
                    cartProduct.Count += count;
                }
            }
            return(MessageResult.CreateSuccessResult());
        }
 public MessageResult LoginOut()
 {
     FormsAuthentication.SignOut();
     return(MessageResult.CreateSuccessResult("注销成功"));
 }
 public MessageResult AddToCart()
 {
     return(MessageResult.CreateSuccessResult());
 }
예제 #13
0
 public MessageResult Save2([FromBody] DemoVo demoVo)
 {
     return(MessageResult.CreateSuccessResult("Save2OK", demoVo));
 }