示例#1
0
        public async Task <ActionResult <LoanChequeRespObj> > AddUpdateLoanCheque()
        {
            try
            {
                var postedFile = _httpContextAccessor.HttpContext.Request.Form.Files;
                //var fileName = _httpContextAccessor.HttpContext.Request.Form.Files["generalUpload"].FileName;
                //var fileExtention = Path.GetExtension(fileName);
                var end          = Convert.ToString(_httpContextAccessor.HttpContext.Request.Form["end"]);
                var loanChequeId = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.Form["loanChequeId"]);
                var loanId       = Convert.ToInt32(_httpContextAccessor.HttpContext.Request.Form["loanApplicationId"]);
                var start        = Convert.ToString(_httpContextAccessor.HttpContext.Request.Form["start"]);

                var byteArray = new byte[0];
                foreach (var fileBit in postedFile)
                {
                    if (fileBit.Length > 0)
                    {
                        using (var ms = new MemoryStream())
                        {
                            await fileBit.CopyToAsync(ms);

                            byteArray = ms.ToArray();
                        }
                    }
                }

                var user = await _serverRequest.UserDataAsync();

                var createdBy = user.UserName;

                var model = new loan_cheque_obj
                {
                    LoanChequeId  = loanChequeId,
                    LoanId        = loanId,
                    GeneralUpload = byteArray,
                    End           = end,
                    Start         = start,
                    CreatedBy     = createdBy
                };

                var response = _repo.AddUpdateLoanCheque(model);

                return(new LoanChequeRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = response ? true : false, Message = new APIResponseMessage {
                            FriendlyMessage = response ? $"Successful" : "Unsuccessful"
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                var errorCode = ErrorID.Generate(5);
                _logger.Error($"ErrorID : {errorCode} Ex : {ex?.Message ?? ex?.InnerException?.Message} ErrorStack : {ex?.StackTrace}");
                return(new LoanChequeRespObj
                {
                    Status = new APIResponseStatus {
                        IsSuccessful = false, Message = new APIResponseMessage {
                            FriendlyMessage = "Error Occurred", TechnicalMessage = ex?.Message, MessageId = errorCode
                        }
                    }
                });
            }
        }