Exemplo n.º 1
0
 /// <summary>
 /// 确保成功执行
 /// </summary>
 /// <param name="apiResult"></param>
 public static void EnsureSuccess(this ApiResultBase apiResult)
 {
     if (!apiResult.IsSuccess())
     {
         throw new WxSdkException(apiResult.GetFriendlyMessage());
     }
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Add([FromForm] ProductsAddInput model)
        {
            var fileName = "";

            if (model?.Image != null)
            {
                var formFile = model?.Image;
                fileName = ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim('"');
                string filePath = _environment.WebRootPath + $@"\Files\Pictures\";
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                fileName = string.Format("{0}.{1}", Guid.NewGuid(), fileName.Split('.')[1]);
                string fileFullName = filePath + fileName;
                using (FileStream fs = new FileStream(fileFullName, FileMode.Create))
                {
                    await formFile.CopyToAsync(fs);

                    fs.Flush();
                }
            }
            string imgpath    = $"/src/Pictures/{fileName}";
            var    adminmodel = _mapper.Map <Products>(model);

            adminmodel.ImageUrl = imgpath;

            var optresult = await _service.AddAsync(adminmodel);

            var result = ApiResultBase.GetInstance(optresult ? ResultCode.Access : ResultCode.Fail, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetAll(BaseInput model)
        {
            var optresult = await _service.GetAllAsync();

            var result = ApiResultBase.GetInstance(ResultCode.Access, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Add(ProductClassInput model)
        {
            var adminmodel = _mapper.Map <ProductClass>(model);
            var optresult  = await _service.AddAsync(adminmodel);

            var result = ApiResultBase.GetInstance(optresult ? ResultCode.Access : ResultCode.Fail, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Register(RegisterInput model)
        {
            var adminmodel = _mapper.Map <AdminInfo>(model);
            var optresult  = await _accountService.AddAsync(adminmodel);

            var result = ApiResultBase.GetInstance(optresult ? ResultCode.Access : ResultCode.Fail, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> GetById(ContactInfoByIdInput model)
        {
            var optresult = await _contactService.GetById(model.Id);

            var outresult = _mapper.Map <ContactInfoOutput>(optresult);
            //outresult.WeChat = Convert.ToBase64String(optresult.WeChat);
            var result = ApiResultBase.GetInstance(ResultCode.Access, result: outresult);

            return(Ok(result));
        }
Exemplo n.º 7
0
 public IActionResult Get()
 {
     try
     {
         return(Json(new ApiResultGeneric <IEnumerable <int> >(raffleService.DoRaffle())));
     }
     catch (Exception ex)
     {
         return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InternalServerError)));
     }
 }
 public IActionResult Get()
 {
     try
     {
         return(Json(new ApiResultGeneric <IEnumerable <City> >(mockService.GetCities())));
     }
     catch (Exception ex)
     {
         return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InternalServerError)));
     }
 }
Exemplo n.º 9
0
 public async Task <IActionResult> GetAll(PaginatedBaseInput model)
 {
     return(await Task.Run <IActionResult>(() =>
     {
         int total;
         var optresult = _service.GetPager(model.PageIndex, model.PageSize, out total);
         var resultOut = new PaginatedBaseOutput <Products>(model.PageIndex, model.PageSize, total, optresult);
         var result = ApiResultBase.GetInstance(ResultCode.Access, result: resultOut);
         return Ok(result);
     }));
 }
Exemplo n.º 10
0
 public IActionResult Get(int id)
 {
     try
     {
         var data = mockService.GetCityById(mockService.GetCities(), id);
         return(Json(new ApiResultGeneric <City>(data)));
     }
     catch (Exception ex)
     {
         return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InternalServerError)));
     }
 }
Exemplo n.º 11
0
        public IActionResult Get()
        {
            try
            {
                var users = userService.GetUsers();

                return(Json(new ApiResultGeneric <IEnumerable <User> >(users)));
            }
            catch (Exception ex)
            {
                return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InternalServerError)));
            }
        }
Exemplo n.º 12
0
        public async Task <IActionResult> Login(LoginInput model)
        {
            object obj = null;

            if (string.IsNullOrWhiteSpace(obj?.ToString()))
            {
            }

            var optresult = await _accountService.LoginAsync(model.LoginName, model.PassWord);

            var result = ApiResultBase.GetInstance(ResultCode.Access, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 13
0
        [AllowAnonymous] //FromForm  -form -data x-wwww-form-urlencoded  [FromBody]:只能传递一个参数
        public async Task <IActionResult> AddUser(AdminUsersDto adminUsers)
        {
            var fileName = "";

            IFormFile formFile = adminUsers.HeadPortrait;

            if (formFile != null)
            {
                fileName = ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim('"');
                string filePath = _environment.WebRootPath + $@"\Files\Pictures\";
                if (!Directory.Exists(filePath))
                {
                    Directory.CreateDirectory(filePath);
                }
                string suffix = fileName.Split('.')[1];
                fileName = Guid.NewGuid() + "." + suffix;
                string fileFullName = filePath + fileName;
                using (FileStream fs = System.IO.File.Create(fileFullName))
                {
                    await formFile.CopyToAsync(fs);

                    fs.Flush();
                }
            }

            string imgpath    = $"/src/Pictures/{fileName}";
            var    adminmodel = _mapper.Map <AdminUsers>(adminUsers);

            adminmodel.HeadPortraitUrl = imgpath;

            var optresult = await _accountService.AddAsync(adminmodel);

            _cacheHelper.SetCache(adminmodel.Id.ToString(), adminmodel, DateTimeOffset.Now.AddHours(1));

            //var product = new ProductInfoDto()
            //{
            //    ID = 1,
            //    //BusinessID = 1,
            //    ClassID = 1,
            //    ProductID = 1
            //};
            //var model = _mapper.Map<ProductInfoToClass>(product);
            var result = ApiResultBase.GetInstance(ResultCode.Access, result: adminmodel);

            return(Ok(result));

            //_accountService.AddAsync()
        }
Exemplo n.º 14
0
        public void OnResourceExecuting(ResourceExecutingContext context)
        {
            //throw new NotImplementedException();
            var keyValuePairs = new List <KeyValuePair <string, object> >();

            try
            {
                if (context.HttpContext.Request.Method.ToLower().Equals("post"))
                {
                    if (context.HttpContext.Request?.Form.Count >= 0)
                    {
                        context.HttpContext.Request.Form?.ToList().ForEach(
                            p =>
                        {
                            keyValuePairs.Add(new KeyValuePair <string, object>(p.Key, p.Value));
                        });
                    }
                }
                else
                {
                    if (context.HttpContext.Request?.Query.Count >= 0)
                    {
                        context.HttpContext.Request.Query?.ToList().ForEach(
                            p =>
                        {
                            keyValuePairs.Add(new KeyValuePair <string, object>(p.Key, p.Value));
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                string s = ex.ToString();
            }
            finally
            {
                //keyValuePairs.AddRange(context.RouteData.Values?.ToList());
                //keyValuePairs.AddRange(context.ActionDescriptor.Parameters);
            }
            if (!ValidateSign(keyValuePairs))
            {
                var result = ApiResultBase.GetInstance(ResultCode.SignValidateFail);
                context.Result = new JsonResult(result);
                //context.HttpContext.Response.Redirect("/api/Error/ResultException?resultcode=1000&message=Validate Sign Fail");
                return;//终止当前请求
            }
        }
Exemplo n.º 15
0
        public IActionResult Login([FromBody] LoginModel model)
        {
            try
            {
                var  password   = Encoding.UTF8.GetString(Convert.FromBase64String(model.Password));
                User loggedUser = userService.CheckUserCredentials(model.Email, password);
                if (loggedUser == null)
                {
                    return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InvalidLogin)));
                }

                return(Json(new ApiResultGeneric <long>(loggedUser.UserID)));
            }
            catch (Exception ex)
            {
                return(Json(ApiResultBase.GetByErrorCode(ErrorCode.InternalServerError)));
            }
        }
Exemplo n.º 16
0
        public IActionResult Post(long Id, IFormFile fi)
        {
            var model = new TechChangeSeachModel();
            var list  = new List <ChilItems>();

            list.Add(new ChilItems()
            {
                Id = Num, Title = "A", IsSelect = false
            });
            list.Add(new ChilItems()
            {
                Id = 2, Title = "B", IsSelect = false
            });
            list.Add(new ChilItems()
            {
                Id = 3, Title = "c", IsSelect = false
            });
            list.Add(new ChilItems()
            {
                Id = 4, Title = "D", IsSelect = false
            });
            list.Add(new ChilItems()
            {
                Id = 5, Title = "F", IsSelect = false
            });

            model.TechLevelList = list;
            model.TechLevelList.Where(p => p.Id == 3).ToList().ForEach(p => p.IsSelect = true);
            model.TechLevelList.OrderBy(p => p.Id).FirstOrDefault().IsSelect           = true;
            //if (Id > 0)
            //{
            //    var obj = _cacheHelper.GetCache<AdminUsers>(Id.ToString());
            //    var result1 = ApiResultBase.GetInstance(ResultCode.Access, result: obj);
            //    return Ok(result1);
            //}
            var result = ApiResultBase.GetInstance(ResultCode.Access, result: model);

            _rabbitMQHelper.Send("hell word");

            var ss = _rabbitMQHelper.Receive();


            return(Ok("1"));
        }
Exemplo n.º 17
0
        public ApiResultBase <string> Update([FromBody] ContactGroup param)
        {
            ApiResultBase <string> res = new ApiResultBase <string>();

            try
            {
                res.RequestTime  = DateTime.Now;
                res.Result       = _service.Update(param);
                res.ResponseTime = DateTime.Now;
                res.QueryTime    = res.ResponseTime - res.RequestTime;
            }
            catch (Exception ex)
            {
                res.StatusCode         = Constant.ErrorCodeSystem.SystemError;
                res.Message            = Constant.ErrorMessage.SystemError;
                res.SystemErrorMessage = ex.Message;
            }

            return(res);
        }
Exemplo n.º 18
0
        public async Task <IActionResult> Add([FromForm] ContactInfoInput model)
        {
            var       adminmodel = _mapper.Map <ContactInfo>(model);
            IFormFile formFile   = model?.WeChat;

            if (formFile != null)
            {
                var fs = formFile.OpenReadStream();
                using (BinaryReader br = new BinaryReader(fs))
                {
                    var imgBytesIn = br.ReadBytes((int)fs.Length);
                    adminmodel.WeChat = imgBytesIn;
                }
            }
            var optresult = await _contactService.AddAsync(adminmodel);

            var result = ApiResultBase.GetInstance(optresult ? ResultCode.Access : ResultCode.Fail, result: optresult);

            return(Ok(result));
        }
Exemplo n.º 19
0
        public ApiResultBase <ContactGroupDTO> Get(string id)
        {
            ApiResultBase <ContactGroupDTO> res = new ApiResultBase <ContactGroupDTO>();

            try
            {
                res.RequestTime  = DateTime.Now;
                res.Result       = _service.GetMapper(id);
                res.ResponseTime = DateTime.Now;
                res.QueryTime    = res.ResponseTime - res.RequestTime;
            }
            catch (Exception ex)
            {
                res.StatusCode         = Constant.ErrorCodeSystem.SystemError;
                res.Message            = Constant.ErrorMessage.SystemError;
                res.SystemErrorMessage = ex.Message;
            }

            return(res);
        }
Exemplo n.º 20
0
        public ApiResultBase <List <ContactGroup> > Fillter([FromBody] List <FillterModel> param)
        {
            ApiResultBase <List <ContactGroup> > res = new ApiResultBase <List <ContactGroup> >();

            try
            {
                res.RequestTime  = DateTime.Now;
                res.Result       = _service.Fillter(param);
                res.ResponseTime = DateTime.Now;
                res.QueryTime    = res.ResponseTime - res.RequestTime;
            }
            catch (Exception ex)
            {
                res.StatusCode         = Constant.ErrorCodeSystem.SystemError;
                res.Message            = Constant.ErrorMessage.SystemError;
                res.SystemErrorMessage = ex.Message;
            }

            return(res);
        }
Exemplo n.º 21
0
        public ApiResultBase <List <SelectItemModel> > GetFund()
        {
            ApiResultBase <List <SelectItemModel> > res = new ApiResultBase <List <SelectItemModel> >();

            try
            {
                res.RequestTime  = DateTime.Now;
                res.Result       = _service.GetFund();
                res.ResponseTime = DateTime.Now;
                res.QueryTime    = res.ResponseTime - res.RequestTime;
            }
            catch (Exception ex)
            {
                res.StatusCode         = Constant.ErrorCodeSystem.SystemError;
                res.Message            = Constant.ErrorMessage.SystemError;
                res.SystemErrorMessage = ex.Message;
            }

            return(res);
        }
Exemplo n.º 22
0
        public ApiResultBase <bool> Delete([FromBody] InvestorContact param)
        {
            ApiResultBase <bool> res = new ApiResultBase <bool>();

            try
            {
                res.RequestTime  = DateTime.Now;
                res.Result       = _service.Delete(param);
                res.ResponseTime = DateTime.Now;
                res.QueryTime    = res.ResponseTime - res.RequestTime;
            }
            catch (Exception ex)
            {
                res.Result             = false;
                res.StatusCode         = Constant.ErrorCodeSystem.SystemError;
                res.Message            = Constant.ErrorMessage.SystemError;
                res.SystemErrorMessage = ex.Message;
            }

            return(res);
        }
Exemplo n.º 23
0
        private async Task <ApiResultBase> LoadWorkoutDetails(Workout workout)
        {
            var result = new ApiResultBase();

            var workoutDetailsFolder = _configuration["WorkoutDetailsFolder"];

            workoutDetailsFolder = Environment.ExpandEnvironmentVariables(workoutDetailsFolder);
            var workoutDetailsFile = Path.Combine(workoutDetailsFolder, $"{workout.Id}.xml");

            if (System.IO.File.Exists(workoutDetailsFile))
            {
                result.Success = WorkoutDetailParser.LoadWorkoutData(workoutDetailsFile, workout);
                result.Message = result.Success ? $"Loaded details for workout {workout.Id} from file" : $"Details were not loaded for workout {workout.Id}";
                return(result);
            }

            using var detailsStream = await WorkoutDetailsRetriever.DownloadWorkoutDetails(_configuration["OnlineWorkoutDetailsSource"], workout.Id)
                                      .ConfigureAwait(false);

            if (detailsStream == null)
            {
                result.Message = $"No details found for workout with Id={workout.Id}!";
                result.Success = false;
                return(result);
            }

            detailsStream.Position = 0;
            WorkoutDetailParser.LoadWorkoutData(detailsStream, workout);

            using var outputFile   = new FileStream(workoutDetailsFile, FileMode.Create);
            detailsStream.Position = 0;
            await detailsStream.CopyToAsync(outputFile)
            .ConfigureAwait(false);

            result.Success = true;
            result.Message = $"Loaded details for workout {workout.Id} from online source";
            return(result);
        }
Exemplo n.º 24
0
 /// <summary>
 ///     系统返回码
 ///     http://www.yunpian.com/api2.0/api-recode.html
 /// </summary>
 /// <param name="result"></param>
 /// <returns></returns>
 public static bool IsSucceed(this ApiResultBase result)
 {
     return(result?.Http_Status_Code == 0);
 }