public IActionResult PaymentAllocation([FromBody] PaymentAllocationInputModel model) { if (!ModelState.IsValid) { return(BadRequest()); } return(Ok(_paymentAppService.PaymentAllocation(model).Result)); }
public async Task <ResponseViewModel> PaymentAllocation(PaymentAllocationInputModel model) { var plot = _plotService.GetByPlotId(model.PlotId); if (plot == null) { return(NotFound(ResponseMessageViewModel.INVALID_PLOT, ResponseErrorCodeStatus.INVALID_PLOT)); } var paymentType = _paymentService.GetAllPaymentTypes().FirstOrDefault(x => x.Id == model.PaymentType); if (paymentType == null) { return(NotFound(ResponseMessageViewModel.INVALID_PAYMENT_TYPE, ResponseErrorCodeStatus.INVALID_PAYMENT_TYPE)); } var paymentMethod = _paymentService.GetAllPaymentMethods().FirstOrDefault(x => x.Id == model.PaymentMethodId); if (paymentMethod == null) { return(NotFound(ResponseMessageViewModel.INVALID_PAYMENT_METHOD, ResponseErrorCodeStatus.INVALID_PAYMENT_METHOD)); } FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(model.Receipt, $"{Helper.RandomNumber(10)}", $"{Helper.RandomNumber(10)}", FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); model.Receipt = uploadResult.Path; } catch (Exception e) { return(Failed(ResponseMessageViewModel.UNABLE_TO_UPLOAD_RECEIPT, ResponseErrorCodeStatus.UNABLE_TO_UPLOAD_RECEIPT)); } var allocation = _paymentService.Allocate(_mapper.Map <PaymentAllocationInputModel, PaymentAllocation>(model)); allocation.PaymentStatusId = (int)PaymentStatusEnum.PENDING; var user = await _userService.GetCurrentLoggedOnUserAsync(); allocation.AppUserId = user.Id; var created = _paymentService.Allocate(allocation); return(Ok(_mapper.Map <PaymentAllocation, PaymentAllocationViewModel>(created))); }