Exemplo n.º 1
0
        public void sendApiRequestAsync(
            Dictionary <object, object> context, RequestInputModel paramBean, ResponseCallBack callback)
        {
            string validate = paramBean != null?paramBean.validateParam() : "";

            Config Config         = (Config)context[Constant.CONFIG_CONTEXT_KEY];
            string configValidate = Config.validateParam();

            if (!StringUtil.isEmpty(validate) || !StringUtil.isEmpty(configValidate))
            {
                if (StringUtil.isEmpty(validate))
                {
                    validate = configValidate;
                }
                OutputModel Out = ParamInvokeUtil.getOutputModel(callback);
                HttpRequestClient.fillResponseCallbackModel(Constant.REQUEST_ERROR_CODE, validate, Out);
                callback.onAPIResponse(Out);
            }
            else
            {
                HttpWebRequest request = buildRequest(context, paramBean);
                HttpRequestClient.getInstance()
                .requestActionAsync(request, Config.isSafeOkHttp(), callback);
            }
        }
Exemplo n.º 2
0
        public OutputModel sendApiRequest(Dictionary <object, object> context, RequestInputModel paramBean, Type outputClass)
        {
            string validate = paramBean != null?paramBean.validateParam() : "";

            EvnContext evnContext  = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];
            string     evnValidate = evnContext.validateParam();

            if (!QSStringUtil.isEmpty(validate) || !QSStringUtil.isEmpty(evnValidate))
            {
                if (QSStringUtil.isEmpty(validate))
                {
                    validate = evnValidate;
                }
                try
                {
                    OutputModel model = (OutputModel)Activator.CreateInstance(outputClass);
                    QSHttpRequestClient.fillResponseCallbackModel(QSConstant.REQUEST_ERROR_CODE, validate, model);
                    return(model);
                }
                catch (Exception e)
                {
                    logger.Fatal(e.Message);
                    throw new QSException(e.Message);
                }
            }
            else
            {
                HttpWebRequest request = buildRequest(context, paramBean);
                return(QSHttpRequestClient.getInstance().requestAction(request, evnContext.isSafeOkHttp(), outputClass));
            }
        }
Exemplo n.º 3
0
        public void sendApiRequestAsync(
            Dictionary <object, object> context, RequestInputModel paramBean, ResponseCallBack callback)
        {
            string validate = paramBean != null?paramBean.validateParam() : "";

            EvnContext evnContext  = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];
            string     evnValidate = evnContext.validateParam();

            if (!QSStringUtil.isEmpty(validate) || !QSStringUtil.isEmpty(evnValidate))
            {
                if (QSStringUtil.isEmpty(validate))
                {
                    validate = evnValidate;
                }
                OutputModel Out = QSParamInvokeUtil.getOutputModel(callback);
                QSHttpRequestClient.fillResponseCallbackModel(QSConstant.REQUEST_ERROR_CODE, validate, Out);
                callback.onAPIResponse(Out);
            }
            else
            {
                HttpWebRequest request = buildRequest(context, paramBean);
                QSHttpRequestClient.getInstance()
                .requestActionAsync(request, evnContext.isSafeOkHttp(), callback);
            }
        }
Exemplo n.º 4
0
        public void TestGetRequestById()
        {
            RequestInputModel inputModel = new RequestInputModel
            {
                BloodGroup  = "A+",
                Description = "",
                AuthorId    = "1",
                CenterId    = "2"
            };
            var result = new Request()
            {
                Description = inputModel.Description,
                BloodGroup  = inputModel.BloodGroup
            };
            var service = new Mock <IRequestService>();

            service.Setup(x => x.AddNewRequestToCenter(inputModel))
            .Returns(false);

            service.Setup(x => x.GetRequestById("1"))
            .Returns(new Request()
            {
                Id = "1"
            });

            service.Object.AddNewRequestToCenter(inputModel);
            var resultCheck = service.Object.GetRequestById("1");

            Assert.NotNull(resultCheck);
        }
        public bool AddNewRequestToCenter(RequestInputModel inputModel)
        {
            Center  center  = this.centerService.GetCenterById(inputModel.CenterId);
            Request request = null;

            if (inputModel.Description.Trim() != "" && inputModel.BloodGroup.Trim() != "")
            {
                request = new Request()
                {
                    Description = inputModel.Description,
                    Center      = center,
                    BloodGroup  = inputModel.BloodGroup
                };

                this.dbContext.Requests.Add(request);
                this.dbContext.SaveChanges();

                var allPotentialDonors = this.userService.GetAllPotentialDonors(request.BloodGroup);
                var sender             = this.userService.GetUserById(inputModel.AuthorId);
                foreach (ApplicationUser receiver in allPotentialDonors)
                {
                    this.notificationService.AddNotification(request.Description, receiver.Id);
                    this.SendEmail(sender, receiver, request.Description);
                }
                return(true);
            }
            return(false);
        }
Exemplo n.º 6
0
        public async Task <ResponseViewModel> CreateRequest(RequestInputModel request)
        {
            var query = _requestRepository.GetRequestTypes().FirstOrDefault(x => x.Id == request.RequestTypeId);

            if (query == null)
            {
                return(NotFound(ResponseMessageViewModel.INVALID_REQUEST_TYPE, ResponseErrorCodeStatus.INVALID_REQUEST_TYPE));
            }

            var currentUser = await _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString());

            var mappedResult = _mapper.Map <RequestInputModel, Request>(request);

            mappedResult.AppUserId = currentUser.Id;

            mappedResult.RequestStatusId = (int)RequestStatusEnum.PENDING;

            mappedResult.DateCreated = DateTime.Now;

            var result = _requestRepository.CreateAndReturn(mappedResult);

            result = _requestRepository.GetAllRequests().FirstOrDefault(x => x.Id == result.Id);

            return(Ok(_mapper.Map <Request, RequestViewModel>(result)));
        }
Exemplo n.º 7
0
        public async Task CreateAsync(RequestInputModel input, string userId, string rootPath)
        {
            var requesterId = this.institutionsService.GetByUserId(userId).Id;

            var request = new IssueRequest
            {
                IssueId        = input.IssueId,
                RequesterId    = requesterId,
                IsApproved     = null,
                IsSolveRequest = input.IsSolveRequest,
                Description    = input.Description,
            };

            if (input.Attachments != null && input.Attachments.Any())
            {
                foreach (var att in input.Attachments)
                {
                    var attachment = await this.attService.CreateAsync(userId, rootPath, att);

                    var requestAttachment = new IssueRequestAttachment
                    {
                        Attachment   = attachment,
                        IssueRequest = request,
                    };

                    await this.issueRequestAttsService.AddAsync(requestAttachment);

                    await this.attRepo.AddAsync(attachment);
                }
            }

            await this.requestsRepo.AddAsync(request);

            await this.requestsRepo.SaveChangesAsync();
        }
Exemplo n.º 8
0
        public OutputModel sendApiRequest(Dictionary <object, object> context, RequestInputModel paramBean, Type outputClass)
        {
            string validate = paramBean != null?paramBean.validateParam() : "";

            Config Config         = (Config)context[Constant.CONFIG_CONTEXT_KEY];
            string configValidate = Config.validateParam();

            if (!StringUtil.isEmpty(validate) || !StringUtil.isEmpty(configValidate))
            {
                if (StringUtil.isEmpty(validate))
                {
                    validate = configValidate;
                }
                try
                {
                    OutputModel model = (OutputModel)Activator.CreateInstance(outputClass);
                    HttpRequestClient.fillResponseCallbackModel(Constant.REQUEST_ERROR_CODE, validate, model);
                    return(model);
                }
                catch (Exception e)
                {
                    logger.Fatal(e.Message);
                    throw new QCException(e.Message);
                }
            }
            else
            {
                HttpWebRequest request = buildRequest(context, paramBean);
                return(HttpRequestClient.getInstance().requestAction(request, Config.isSafeOkHttp(), outputClass));
            }
        }
Exemplo n.º 9
0
 public IActionResult Create(RequestInputModel inputModel)
 {
     if (this.ModelState.IsValid)
     {
         this.requestService.AddNewRequestToCenter(inputModel);
     }
     return(this.Redirect("/"));
 }
Exemplo n.º 10
0
 public IActionResult Edit(RequestInputModel inputModel)
 {
     if (this.ModelState.IsValid)
     {
         this.requestService.EditRequest(inputModel.Id, inputModel);
     }
     return(this.Redirect("/Center/Details/" + inputModel.CenterId));
 }
Exemplo n.º 11
0
        public IActionResult NewRequest([FromBody] RequestInputModel request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            return(Ok(_requestAppService.CreateRequest(request).Result));
        }
Exemplo n.º 12
0
        public IActionResult New(int id)
        {
            var viewModel = new RequestInputModel
            {
                IssueId = id,
            };

            return(this.View(viewModel));
        }
Exemplo n.º 13
0
        public void FinishRequest(string macAddress, RequestInputModel model) 
        {
            var request = new RestRequest("v1/signboards/{macAddress}/requests", Method.POST);
            request.RequestFormat = RestSharp.DataFormat.Json;
            request.AddUrlSegment("macAddress", macAddress);
            request.AddBody(model);

            var response = Client.Execute<RequestModel>(request);
        }
Exemplo n.º 14
0
        private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params)
        {
            Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY];
            string zone   = (string)context[Constant.PARAM_KEY_REQUEST_ZONE];

            Dictionary <object, object> paramsQuery   = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsBody    = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_BODY);
            Dictionary <object, object> paramsHeaders = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_HEADER);

            paramsHeaders.Add("action", context["action"]);
            if (paramsHeaders.ContainsKey("zone"))
            {
                paramsHeaders["zone"] = zone;
            }
            else
            {
                paramsHeaders.Add("zone", zone);
            }

            if (context.ContainsKey(Constant.PARAM_KEY_USER_AGENT))
            {
                paramsHeaders.Add(Constant.PARAM_KEY_USER_AGENT, context[Constant.PARAM_KEY_USER_AGENT]);
            }

            String requestApi = (String)context[Constant.PARAM_KEY_REQUEST_APINAME];
            //string FileBody = GetBodyFile(context[Constant.PARAM_KEY_OBJECT_NAME].ToString()).ToString();

            string method      = (string)context[Constant.PARAM_KEY_REQUEST_METHOD];
            string requestPath = Config.getHost() + Config.getUri();
            string singedUrl   =
                SignatureUtil.getURL(
                    Config.getAccessKey(),
                    Config.getAccessSecret(),
                    method,
                    requestPath,
                    paramsQuery,
                    paramsHeaders);

            singedUrl = Config.getProtocol() + "://" + singedUrl;

            logger.Info(singedUrl);

            //System.Console.WriteLine(singedUrl);
            HttpWebRequest request =
                HttpRequestClient.getInstance()
                .buildCloudRequest(method, paramsBody, singedUrl, paramsHeaders);

            return(request);
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Edit(string id)
        {
            var me = await this.userManager.GetUserAsync(HttpContext.User);

            Request           request = this.requestService.GetRequestById(id);
            RequestInputModel model   = new RequestInputModel
            {
                Id          = id,
                BloodGroup  = request.BloodGroup,
                Description = request.Description,
                CenterId    = request.CenterId,
                AuthorId    = me.Id
            };

            return(this.View(model));
        }
Exemplo n.º 16
0
        public async Task <IActionResult> New(RequestInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            var rootPath = $"{this.environment.WebRootPath}";

            try
            {
                var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
                await this.requestsService.CreateAsync(input, userId, rootPath);
            }
            catch (Exception ex)
            {
                this.ModelState.AddModelError(string.Empty, ex.Message);
                return(this.View(input));
            }

            return(this.Redirect($"/Issues/{input.IssueId}"));
        }
Exemplo n.º 17
0
        public void TestCreateRequestWithInvalidData()
        {
            RequestInputModel inputModel = new RequestInputModel
            {
                BloodGroup  = "A+",
                Description = "",
                AuthorId    = "1",
                CenterId    = "2"
            };
            var result = new Request()
            {
                Description = inputModel.Description,
                BloodGroup  = inputModel.BloodGroup
            };
            var service = new Mock <IRequestService>();

            service.Setup(x => x.AddNewRequestToCenter(inputModel))
            .Returns(false);

            var resultCheck = service.Object.AddNewRequestToCenter(inputModel);

            Assert.False(resultCheck);
        }
        public bool EditRequest(string requestId, RequestInputModel inputModel)
        {
            Center center = this.centerService.GetCenterById(inputModel.CenterId);

            Request request = this.dbContext.Requests.FirstOrDefault(x => x.Id == requestId);

            if (request != null)
            {
                request.Description = inputModel.Description;
                request.Center      = center;
                request.BloodGroup  = inputModel.BloodGroup;

                this.dbContext.SaveChanges();

                var allPotentialDonors = this.userService.GetAllPotentialDonors(request.BloodGroup);
                var sender             = this.userService.GetUserById(inputModel.AuthorId);
                foreach (ApplicationUser receiver in allPotentialDonors)
                {
                    this.SendEmail(sender, receiver, request.Description);
                }
                return(true);
            }
            return(false);
        }
        public static String getExpireAuth(Dictionary <object, object> context, int expiresSecond, RequestInputModel Params)
        {
            Config Config = (Config)context[Constant.CONFIG_CONTEXT_KEY];

            Dictionary <object, object> paramsQuery   = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsHeaders = ParamInvokeUtil.getRequestParams(Params, Constant.PARAM_TYPE_HEADER);

            paramsHeaders.Remove(Constant.HEADER_PARAM_KEY_DATE);
            paramsHeaders.Clear();
            paramsHeaders.Add(Constant.HEADER_PARAM_KEY_EXPIRES, expiresSecond + "");

            string method = (string)context[Constant.PARAM_KEY_REQUEST_METHOD];

            string requestPath = Config.getHost() + Config.getUri();
            string authSign    = getSignature(
                Config.getAccessKey(),
                Config.getAccessSecret(),
                method,
                requestPath,
                paramsQuery,
                paramsHeaders);

            return(HttpUtility.UrlEncode(authSign, Encoding.GetEncoding(Constant.ENCODING_UTF8)));
        }
Exemplo n.º 20
0
 public ResponseViewModel UpdateRequest(RequestInputModel request)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 21
0
        public static String getExpireAuth(Dictionary <object, object> context, int expiresSecond, RequestInputModel Params)
        {
            EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];

            Dictionary <object, object> paramsQuery   = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER);

            paramsHeaders.Remove(QSConstant.HEADER_PARAM_KEY_DATE);
            paramsHeaders.Clear();
            paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_EXPIRES, expiresSecond + "");

            string method      = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD];
            string bucketName  = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME];
            string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH];

            requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName);
            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, (string)context[QSConstant.PARAM_KEY_OBJECT_NAME]);
            }
            string authSign = getSignature(
                evnContext.getAccessKey(),
                evnContext.getAccessSecret(),
                method,
                requestPath,
                paramsQuery,
                paramsHeaders);

            return(HttpUtility.UrlEncode(authSign, Encoding.GetEncoding(QSConstant.ENCODING_UTF8)));
        }
Exemplo n.º 22
0
        private HttpWebRequest buildRequest(Dictionary <object, object> context, RequestInputModel Params)
        {
            EvnContext evnContext = (EvnContext)context[QSConstant.EVN_CONTEXT_KEY];
            string     zone       = (string)context[QSConstant.PARAM_KEY_REQUEST_ZONE];

            Dictionary <object, object> paramsQuery   = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_QUERY);
            Dictionary <object, object> paramsBody    = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_BODY);
            Dictionary <object, object> paramsHeaders = QSParamInvokeUtil.getRequestParams(Params, QSConstant.PARAM_TYPE_HEADER);

            if (context.ContainsKey(QSConstant.PARAM_KEY_USER_AGENT))
            {
                paramsHeaders.Add(QSConstant.PARAM_KEY_USER_AGENT, context[QSConstant.PARAM_KEY_USER_AGENT]);
            }

            String requestApi = (String)context[QSConstant.PARAM_KEY_REQUEST_APINAME];

            //string FileBody = GetBodyFile(context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString()).ToString();
            paramsHeaders = initHeadContentMd5(requestApi, paramsBody, paramsHeaders);

            string method      = (string)context[QSConstant.PARAM_KEY_REQUEST_METHOD];
            string bucketName  = (string)context[QSConstant.PARAM_KEY_BUCKET_NAME];
            string requestPath = (string)context[QSConstant.PARAM_KEY_REQUEST_PATH];

            string objectName = "";

            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                objectName = context[QSConstant.PARAM_KEY_OBJECT_NAME].ToString();
            }
            if (!paramsHeaders.ContainsKey(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE))
            {
                paramsHeaders.Add(QSConstant.HEADER_PARAM_KEY_CONTENTTYPE, MimeMapping.GetMimeMapping(objectName));
            }

            if (context.ContainsKey(QSConstant.PARAM_KEY_OBJECT_NAME))
            {
                requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName);
                requestPath = requestPath.Replace(QSConstant.OBJECT_NAME_REPLACE, QSStringUtil.urlCharactersEncoding(objectName));
            }
            else
            {
                requestPath = requestPath.Replace(QSConstant.BUCKET_NAME_REPLACE, bucketName + "/");
            }

            string authSign =
                QSSignatureUtil.getAuth(
                    evnContext.getAccessKey(),
                    evnContext.getAccessSecret(),
                    method,
                    requestPath,
                    paramsQuery,
                    paramsHeaders);
            string requestSuffixPath = getRequestSuffixPath((string)context[QSConstant.PARAM_KEY_REQUEST_PATH], bucketName, objectName);

            paramsHeaders.Add("Authorization", authSign);
            logger.Info(authSign);
            string singedUrl =
                getSignedUrl(
                    evnContext.getRequestUrl(),
                    zone,
                    bucketName,
                    paramsQuery,
                    requestSuffixPath);

            if (singedUrl.IndexOf("&upload_id") != -1)//?part_number=0&upload_id=1asfdsf
            {
                if (singedUrl.IndexOf("upload_id") > singedUrl.IndexOf("part_number"))
                {
                    String temp1 = singedUrl.Substring(singedUrl.IndexOf("part_number"), singedUrl.IndexOf("&upload_id") - singedUrl.IndexOf("part_number"));
                    String temp2 = singedUrl.Substring(singedUrl.IndexOf("upload_id"), singedUrl.Length - singedUrl.IndexOf("upload_id"));
                    singedUrl = singedUrl.Substring(0, singedUrl.IndexOf("?") + 1) + temp2 + "&" + temp1; //singedUrl.Replace(temp1, temp2).Replace(temp2,temp1);
                }
            }
            logger.Info(singedUrl);
            if (QSConstant.PARAM_KEY_REQUEST_API_MULTIPART.Equals(requestApi))
            {
                HttpWebRequest request =
                    QSHttpRequestClient.getInstance()
                    .buildStorMultiUpload(
                        method, paramsBody, singedUrl, paramsHeaders, paramsQuery);
                return(request);
            }
            else
            {
                //System.Console.WriteLine(singedUrl);
                HttpWebRequest request =
                    QSHttpRequestClient.getInstance()
                    .buildStorRequest(method, paramsBody, singedUrl, paramsHeaders);
                return(request);
            }
        }