public async Task <ResponseViewModel> CreateNew(MobilizationInputModel model) { var user = await _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString()); var query = _plotService.AllPlots().FirstOrDefault(x => x.Id == model.PlotId); if (query == null) { return(NotFound(ResponseMessageViewModel.INVALID_PLOT, ResponseErrorCodeStatus.INVALID_PLOT)); } model.AppUserId = user.Id; if (!string.IsNullOrEmpty(model.Document)) { var uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _setting) .UploadDocumentAsync(FileDocument.Create(model.Document, "Mobilization", $"{user.GUID}", FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); if (uploadResult == null) { return(Failed(ResponseMessageViewModel.ERROR_UPLOADING_FILE, ResponseErrorCodeStatus.ERROR_UPLOADING_FILE)); } model.Document = uploadResult.Path; } var mappedResult = _mobilizationService.CreateNew(_mapper.Map <MobilizationInputModel, Mobilization>(model)); var result = _mapper.Map <Mobilization, MobilizationViewModel>(mappedResult); return(Ok(result)); }
public async Task <string> GenerateCodeAsync() { Url generator = new Url("https://www.oidc.com"); string payload = generator.ToString(); string link = string.Empty; QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q); Base64QRCode qrCode = new Base64QRCode(qrCodeData); string qrCodeImageAsBase64 = qrCode.GetGraphic(20); FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(qrCodeImageAsBase64, $"{Helper.RandomNumber(10)}", $"{Helper.RandomNumber(10)}", FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); link = uploadResult.Path; } catch (Exception e) { link = string.Empty; } return(link); }
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 <FileDocument> UploadDocumentAsync(FileDocument document) { try { CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(); CancellationToken token = cancellationTokenSource.Token; var profilePhotoPath = string.Empty; var bytes = Convert.FromBase64String(document.File); var uniqueFileName = Utility.GetUniqueFileName(document.FileNameWithExtension); var parentFolder = Path.Combine(_setting.UploadDrive, _setting.DriveName); if (!Directory.Exists(parentFolder)) { Directory.CreateDirectory(parentFolder); } profilePhotoPath = Path.Combine(parentFolder, uniqueFileName); using (var imageFile = new FileStream(profilePhotoPath, FileMode.Create)) { imageFile.Write(bytes, 0, bytes.Length); imageFile.Flush(); var stream = new FileStream(profilePhotoPath, FileMode.Open); var task = new FirebaseStorage(_setting.FireBaseBucket) .Child("oidc") .Child(document.Path) .Child(document.FileNameWithExtension) .PutAsync(stream, token, document.DocumentType.MimeType); task.Progress.ProgressChanged += (s, e) => Console.WriteLine($"Progress: {e.Percentage} %"); var result = await task; return(FileDocument.Create(null, document.Name, result, document.DocumentType)); } } catch (Exception e) { return(null); } }
public async Task <ResponseViewModel> CreateNewJob(JobInputModel model) { //var jobStatus = _jobRepository.GetJobStatuses().FirstOrDefault(x => x.Id == model.JobStatusId); //if(jobStatus == null) //{ // return Failed(ResponseMessageViewModel.INVALID_JOB_STATUS, ResponseErrorCodeStatus.INVALID_JOB_STATUS); //} var jobType = _jobRepository.GetJobTypes().FirstOrDefault(x => x.Id == model.JobTypeId); //model.ValidityPeriod = DateTime.Now; if (jobType == null) { return(Failed(ResponseMessageViewModel.INVALID_JOB_TYPE, ResponseErrorCodeStatus.INVALID_JOB_TYPE)); } var mappedResult = _mapper.Map <JobInputModel, Job>(model); var user = _userService.GetCurrentLoggedOnUserAsync().Result; mappedResult.AppUserId = user.Id; FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(model.Document, "Job", $"{user.GUID}", FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); mappedResult.Document = uploadResult.Path; } catch (Exception e) { return(Failed(ResponseMessageViewModel.ERROR_UPLOADING_FILE, ResponseErrorCodeStatus.ERROR_UPLOADING_FILE)); } var result = _mapper.Map <Job, JobViewModel>(_jobRepository.CreateJob(mappedResult)); return(Ok(result)); }
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)))); }
/// <summary> /// This Method Update Vendor's Information /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <ResponseViewModel> UpdateVendorAsync(VendorInputModel model) { try { AppUser currentUser = await _userManager.FindByIdAsync(_httpContextAccessor.HttpContext.User.GetLoggedInUserId <int>().ToString()); if (!currentUser.EmailConfirmed) { return(Failed(ResponseMessageViewModel.EMAIL_NOT_CONFIRMED, ResponseErrorCodeStatus.EMAIL_NOT_CONFIRMED)); } if (currentUser != null) { currentUser.FirstName = model.FirstName; currentUser.LastName = model.LastName; currentUser.MiddleName = model.MiddleName; currentUser.PhoneNumber = model.PhoneNumber; currentUser.ResidentialAddress = model.ResidentialAddress; currentUser.MailingAddress = model.MailingAddress; if (!string.IsNullOrEmpty(model.ProfilePhoto) && model.IsProfilePhotoChanged) { FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(model.ProfilePhoto, $"photo-{currentUser.Id}", currentUser.GUID, FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); } catch (Exception e) { return(Failed(ResponseMessageViewModel.ERROR_UPLOADING_FILE, ResponseErrorCodeStatus.ERROR_UPLOADING_FILE)); } currentUser.ProfilePhoto = uploadResult.Path; currentUser.HasUploadedProfilePhoto = !string.IsNullOrEmpty(currentUser.ProfilePhoto); } if (!string.IsNullOrEmpty(model.IdentityDocument) && model.IsIdentityDocumentChanged) { FileDocument uploadResult = FileDocument.Create(); try { uploadResult = await BaseContentServer .Build(ContentServerTypeEnum.FIREBASE, _settings) .UploadDocumentAsync(FileDocument.Create(model.IdentityDocument, $"document-{currentUser.Id}", currentUser.GUID, FileDocumentType.GetDocumentType(MIMETYPE.IMAGE))); } catch (Exception e) { return(Failed(ResponseMessageViewModel.ERROR_UPLOADING_FILE, ResponseErrorCodeStatus.ERROR_UPLOADING_FILE)); } currentUser.IdentityDocument = uploadResult.Path; currentUser.HasUploadedDocument = !string.IsNullOrEmpty(currentUser.IdentityDocument); } var gender = _utilityRepository.GetGenderByName(model.Gender); if (gender == null) { return(Failed(ResponseMessageViewModel.INVALID_GENDER, ResponseErrorCodeStatus.INVALID_GENDER)); } currentUser.GenderId = gender.Id; var state = _stateService.GetState(model.StateOfOriginId); if (state == null) { return(Failed(ResponseMessageViewModel.INVALID_STATE, ResponseErrorCodeStatus.INVALID_STATE)); } currentUser.StateOfOriginId = state.Id; if (model.NextOfKin != null) { var nextOfKin = _mapper.Map <VendorNextOfKinInputModel, NextOfKin>(model.NextOfKin); nextOfKin.AppUserId = currentUser.Id; var nextOfKinGender = _utilityRepository.GetGenderByName(model.NextOfKin.Gender); if (nextOfKinGender == null) { return(Failed(ResponseMessageViewModel.INVALID_NEXT_OF_KIN_GENDER, ResponseErrorCodeStatus.INVALID_NEXT_OF_KIN_GENDER)); } nextOfKin.GenderId = nextOfKinGender.Id; _utilityRepository.AddNextOfKin(nextOfKin); } var userType = _utilityRepository.GetOrganizationType(model.UserTypeId); if (userType == null) { return(Failed(ResponseMessageViewModel.INVALID_ORGANIZATION_TYPE, ResponseErrorCodeStatus.INVALID_ORGANIZATION_TYPE)); } currentUser.OrganizationTypeId = model.UserTypeId; if (model.UserTypeId == (int)OrganizationEnumType.CORPORATE) { if (string.IsNullOrEmpty(model.RCNumber)) { return(Failed(ResponseMessageViewModel.INVALID_RC_NUMBER, ResponseErrorCodeStatus.INVALID_RC_NUMBER)); } currentUser.RCNumber = model.RCNumber; if (string.IsNullOrEmpty(model.OfficeAddress)) { return(Failed(ResponseMessageViewModel.INVALID_OFFICE_ADDRESS, ResponseErrorCodeStatus.INVALID_OFFICE_ADDRESS)); } currentUser.OfficeAddress = model.OfficeAddress; if (string.IsNullOrEmpty(model.NameOfEntry)) { return(Failed(ResponseMessageViewModel.INVALID_NAME_NAME_OF_ENTRY, ResponseErrorCodeStatus.INVALID_NAME_NAME_OF_ENTRY)); } currentUser.EntryName = model.NameOfEntry; currentUser.WebsiteUrl = model.WebSiteUrl; } await _userManager.UpdateAsync(currentUser); var mappedResult = _mapper.Map <AppUser, VendorViewModel>(currentUser); return(Ok().AddStatusMessage(ResponseMessageViewModel.SUCCESSFUL).AddData(mappedResult)); } else { return(Failed()); } } catch (Exception e) { return(Create(false, e.Message).AddStatusCode(ResponseErrorCodeStatus.FAIL)); } }