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))); }
public async Task <ResponseViewModel> CreateNewDocument(DocumentInputModel document) { var user = _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString()).Result; var query = _plotService.GetByPlotId(document.PlotId); if (query == null) { return(NotFound(ResponseMessageViewModel.INVALID_PLOT, ResponseErrorCodeStatus.INVALID_PLOT)); } var documentType = _documentService.GetDocumentTypes().FirstOrDefault(x => x.Id == document.DocumentType); if (documentType == null) { return(NotFound(ResponseMessageViewModel.INVALID_DOCUMENT_TYPE, ResponseErrorCodeStatus.INVALID_DOCUMENT_TYPE)); } FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(document.Document, document.GetDocumentType(), $"{user.GUID}", FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); } catch (Exception e) { return(Failed(ResponseMessageViewModel.ERROR_UPLOADING_FILE, ResponseErrorCodeStatus.ERROR_UPLOADING_FILE)); } var mappedResult = _mapper.Map <DocumentInputModel, Document>(document); mappedResult.AppUserId = user.Id; mappedResult.Name = uploadResult.Path; mappedResult.PlotId = 1010; return(Ok(_mapper.Map <Document, DocumentViewModel>(_documentService.CreateDocument(mappedResult)))); }