Example #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            var result = new ApiResult <PagedList <DocumentDetails> >();

            log.LogInformation("Start get Documents...");

            var investorId = req.Query.GetIntValue("investorId");

            if (!investorId.HasValue)
            {
                result.Success = false;
                result.AddError("The investorId parameter is not provided or invalid format");
                return(new BadRequestObjectResult(result));
            }

            var pageNumber = req.Query.GetIntValue("pageNumber");

            if (!pageNumber.HasValue)
            {
                result.Success = false;
                result.AddError("The pageNumber parameter is not valid format");
                return(new BadRequestObjectResult(result));
            }

            var pageSize = req.Query.GetIntValue("pageSize");

            if (!pageSize.HasValue)
            {
                result.Success = false;
                result.AddError("The pageSize parameter is not valid format");
                return(new BadRequestObjectResult(result));
            }

            try
            {
                var list = await _documentDataAccess.GetPagedCorrespondenceByInvestorId(investorId.Value, pageNumber.Value, pageSize.Value);

                result.Data = list;
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.AddError(ex.Message);
                log.LogError(ex.Message);
            }
            finally
            {
                log.LogInformation("End get Documents");
            }

            return(new JsonResult(result));
        }
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Start insert/update function...");

            var result = new ApiResult <Guid>();

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var    doc         = JsonConvert.DeserializeObject <InvestorDocumentFlat>(requestBody);

            if (doc == null)
            {
                result.Success = false;
                result.AddError("The required object of document is not provided or invalid format");
            }
            else
            {
                try
                {
                    result.Data = await _documentDataAccess.InsertUpdateDocument(doc);
                }
                catch (Exception ex)
                {
                    result.Success = false;
                    result.AddError(ex.Message);
                    log.LogError(ex.Message);
                }
                finally
                {
                    log.LogInformation("End insert/update function");
                }
            }

            return(new JsonResult(result));
        }
        public ApiResult<PostSessionResult> Post(PostSessionRequest model)
        {
            Contract.Requires<ArgumentNullException>(model != null);

            LogonCommand command = model.ToLogonCommand();
            LogonResult logonResult = mediator.Send(command);
            var apiResult = new ApiResult<PostSessionResult>();

            apiResult.IsSuccessful = logonResult.IsSuccessful;
            if (logonResult.IsSuccessful)
            {
                apiResult.Data.Id = logonResult.User.Id;
                apiResult.Data.SessionId = "";
                apiResult.Data.Username = logonResult.User.Username;
            }
            else
            {
                apiResult.AddError(new ErrorDef("Invalid credentials."));
            }

            return apiResult;
        }
 public ApiResult<PutTagResult> Put(PutTagRequest model)
 {
     var result = new ApiResult<PutTagResult>(false);
     result.AddError(new ErrorDef("This method has not yet been implemented."));
     return result;
 }