Esempio n. 1
0
        public ApiResult OnSaledProduct(Guid id, string type)
        {
            ApiResult result;

            Model.Entities.Product onSaleingProduct = ProductDao.Query(t => t.ID == id).FirstOrDefault();

            if (type == "downSaledProduct")
            {
                onSaleingProduct.IsSaled = false;
            }
            else
            {
                onSaleingProduct.IsSaled = true;
            }



            int  affectNum       = ProductDao.Submit();
            bool isUpdateSuccess = affectNum > 0 ? true : false;

            if (isUpdateSuccess)
            {
                result = ApiResult.SuccessResult(type, "");
            }
            else
            {
                result = ApiResult.FailedResult("删除失败");
            }

            return(result);
        }
Esempio n. 2
0
 private JsonResult LoginTimeoutResult()
 {
     return(new JsonResult()
     {
         Data = ApiResult.FailedResult("登陆超时,请重新登陆", "登陆超时,请重新登陆")
     });
 }
Esempio n. 3
0
        public ApiResult Edit(Band band)
        {
            Band      oldBand = ProductBandsDao.Query(t => t.ID == band.ID).FirstOrDefault();
            ApiResult result;

            //在赋值
            oldBand.Description      = band.Description;
            oldBand.BandName         = band.BandName;
            oldBand.BandNum          = band.BandNum;
            oldBand.EnglishFirstChar = band.EnglishFirstChar;
            oldBand.EnglishName      = band.EnglishName;

            ProductBandsDao.Update(oldBand, false);
            int affectNum = ProductBandsDao.Submit();

            bool isUpdateSuccess = affectNum > 0 ? true : false;

            if (isUpdateSuccess)
            {
                result = ApiResult.SuccessResult(band, "编辑品牌成功");
            }
            else
            {
                result = ApiResult.FailedResult("编辑品牌失败");
            }

            return(result);
        }
Esempio n. 4
0
        public ApiResult Remove(string idList)
        {
            ApiResult result;

            var idArr = idList.Split(',');

            if (idArr.Any() && !string.IsNullOrWhiteSpace(idArr[0]))
            {
                var ids = idArr.Select(id => id.ToGuid());

                foreach (var id in ids)
                {
                    ProductDao.Delete(id, false);
                }

                if (ProductDao.Submit() != -1)
                {
                    return(result = ApiResult.SuccessResult(ids.Count(), "删除成功"));
                }
                else
                {
                    return(result = ApiResult.FailedResult("删除失败"));
                }
            }
            else
            {
                return(result = ApiResult.SuccessResult(0, "未选中任何数据"));
            }
        }
Esempio n. 5
0
        public ApiResult Add(Sku sku)
        {
            ApiResult result;

            sku.SkuNum = _String.GetSequence("SKU");


            int affectNum;

            try
            {
                ProductSkuDao.Create(sku, false);
                affectNum = ProductSkuDao.Submit();
            }
            catch (Exception)
            {
                result = ApiResult.FailedResult("添加商品规格失败");
                throw;
            }

            bool isUpdateSuccess = affectNum > 0 ? true : false;

            if (isUpdateSuccess)
            {
                result = ApiResult.SuccessResult(sku, "添加商品规格成功");
            }
            else
            {
                result = ApiResult.FailedResult("添加商品规格失败");
            }

            return(result);
        }
Esempio n. 6
0
        public ApiResult Add(Band band)
        {
            ApiResult result;

            band.BandNum = _String.GetSequence("B");


            int affectNum;

            try
            {
                ProductBandsDao.Create(band, false);
                affectNum = ProductBandsDao.Submit();
            }
            catch (Exception)
            {
                result = ApiResult.FailedResult("添加品牌失败");
                throw;
            }

            bool isUpdateSuccess = affectNum > 0 ? true : false;

            if (isUpdateSuccess)
            {
                result = ApiResult.SuccessResult(band, "添加品牌成功");
            }
            else
            {
                result = ApiResult.FailedResult("添加品牌失败");
            }

            return(result);
        }
Esempio n. 7
0
        private static Task HandleGlobalExceptionAsync(HttpContext context, System.Exception ex)
        {
            ApiResult apiResult = ApiResult.FailedResult(ApiResultCode.SERIVCEERROR, "系统异常");

            context.Response.ContentType = "application/json";
            context.Response.StatusCode  = (int)HttpStatusCode.InternalServerError;
            return(context.Response.WriteAsync(JsonConvert.SerializeObject(apiResult)));
        }
Esempio n. 8
0
        public async Task <ApiResult <LoginResult> > RefreshToken([FromBody] RefreshTokenRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(ApiResult.FailedResult <LoginResult>(ApiResultCode.ARGSERROR, "refreshToken不能为空!"));
            }
            var refreshResult = await tokenService.Refresh(request.RefreshToken, request.AccessToken, DateTime.Now);

            return(ApiResult.SuccessResult(new LoginResult()
            {
                UserName = User.Identity.Name,
                AccessToken = refreshResult?.AccessToken,
                RefreshToken = refreshResult?.RefreshToken?.TokenString
            }));
        }
        public override void OnException(ExceptionContext filterContext)
        {
            var log = LogManager.GetLogger("Filter." + typeof(HandleExceptionFilterAttribute).Name);

            log.Error("执行请求的过程中发生了未经处理的异常", filterContext.Exception);
#if DEBUG
            filterContext.Result = new JsonResult()
            {
                Data = ApiResult.FailedResult("执行请求的过程中发生了未经处理的异常", filterContext.Exception.Message),
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            };
#else
            filterContext.Result = new JsonResult()
            {
                Data = ApiResult.FailedResult("执行请求的过程中发生了未经处理的异常", "详情请查看日志")
            };
#endif
            filterContext.ExceptionHandled = true;
        }
Esempio n. 10
0
        public async Task <ApiResult <bool> > Register([FromBody] RegisterRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(ApiResult.FailedResult <bool>(ApiResultCode.ARGSERROR, ModelState.GetStateError()));
            }
            var user = new UserDto()
            {
                UserName    = request.UserName.Trim(),
                IDNumber    = request.IDNumber.Trim(),
                RealName    = request.RealName?.Trim(),
                NickName    = request.NickName?.Trim(),
                Avatar      = request.Avatar?.Trim(),
                Email       = request.Email?.Trim(),
                MobilePhone = request.MobilePhone.Trim(),
                Password    = request.Password.Trim()
            };
            var result = await userService.CreateUser(user);

            return(ApiResult.SuccessResult(result));
        }
Esempio n. 11
0
        public async Task <ApiResult <LoginResult> > Login([FromBody] LoginRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(ApiResult.FailedResult <LoginResult>(ApiResultCode.ARGSERROR, "用户名或密码不能为空!"));
            }
            var credentialInfo = await userService.IsValidUserCredentials(request.UserName, request.Password);

            if (credentialInfo == null || string.IsNullOrEmpty(credentialInfo.UserName))
            {
                return(ApiResult.FailedResult <LoginResult>(ApiResultCode.PERMISSIONDENIED, "用户名或密码错误!"));
            }
            var userId   = credentialInfo.Id;
            var jwtToken = await tokenService.GenerateTokens(userId, request.UserName, DateTime.Now);

            return(ApiResult.SuccessResult(new LoginResult()
            {
                UserName = request.UserName,
                AccessToken = jwtToken.AccessToken,
                RefreshToken = jwtToken.RefreshToken.TokenString
            }));
        }
Esempio n. 12
0
        public JsonResult Remove(string idList)
        {
            ApiResult result;

            var idArr = idList.Split(',');

            if (idArr.Any() && !string.IsNullOrWhiteSpace(idArr[0]))
            {
                var ids = idArr.Select(id => id.ToGuid());

                foreach (var id in ids)
                {
                    SysUserDemoService.Delete(id);
                }

                result = ApiResult.SuccessResult(ids.Count(), "删除成功");
            }
            else
            {
                result = ApiResult.FailedResult("未选中任何数据");
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 13
0
        public ApiResult Edit(Sku sku)
        {
            Sku       oldSku = ProductSkuDao.Query(t => t.ID == sku.ID).FirstOrDefault();
            ApiResult result;

            //在赋值
            oldSku.SkuName = sku.SkuName;

            ProductSkuDao.Update(oldSku, false);
            int affectNum = ProductSkuDao.Submit();

            bool isUpdateSuccess = affectNum > 0 ? true : false;

            if (isUpdateSuccess)
            {
                result = ApiResult.SuccessResult(sku, "编辑商品规格成功");
            }
            else
            {
                result = ApiResult.FailedResult("编辑商品规格失败");
            }

            return(result);
        }
Esempio n. 14
0
 /// <summary>
 /// 失败结果
 /// </summary>
 /// <param name="code">失败编码</param>
 /// <param name="errMsg">失败信息</param>
 /// <returns></returns>
 public static ApiResult <string> FailedResult(int code, string errMsg = "")
 {
     return(ApiResult <string> .FailedResult(code, errMsg));
 }
Esempio n. 15
0
 protected ApiResult Failure(string msg, string exception)
 {
     return(ApiResult.FailedResult(msg, exception));
 }