public async Task <User> GetUser(string username, string password) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); User user = new User(); string databaseId; string databaseMail; string databasePhoneNumber; string databaseSurename; string databaseName; string databasePassword; string databaseUsername; FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query userQuery = db.Collection("System_User").WhereEqualTo("Username", username).WhereEqualTo("Password", password); QuerySnapshot userQuerySnapshot = await userQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in userQuerySnapshot.Documents) { Console.WriteLine("Document data for {0} document:", documentSnapshot.Id); Dictionary <string, object> userDocument = documentSnapshot.ToDictionary(); userDocument.TryGetTypedValue("Id", out databaseId); userDocument.TryGetTypedValue("Mail", out databaseMail); userDocument.TryGetTypedValue("PhoneNumber", out databasePhoneNumber); userDocument.TryGetTypedValue("Name", out databaseName); userDocument.TryGetTypedValue("Surename", out databaseSurename); userDocument.TryGetTypedValue("Password", out databasePassword); userDocument.TryGetTypedValue("Username", out databaseUsername); user.setUserData(databaseId, databaseMail, databasePhoneNumber, databaseName, databaseSurename, databasePassword, databaseUsername); } return(user); }
public async Task <bool> deleteParticipationFormat(string id) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("ParticipationFormat").Document(id); await docRef.DeleteAsync(); return(true); }
public async Task <bool> deleteUser(string user_Id) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("System_User").Document(user_Id); await docRef.DeleteAsync(); return(true); }
public async Task <bool> deleteMailTemplate(string mail_Template_Id) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("Mail_Template").Document(mail_Template_Id); await docRef.DeleteAsync(); return(true); }
public async Task <bool> deleteEvent(long event_Id) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("Event").Document(event_Id.ToString()); await docRef.DeleteAsync(); return(true); }
public async Task <LastIdentificationNumber> IncreaseLastIdetificationNumber(string domainEntityName) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); LastIdentificationNumber lastIdentificationNumber = await getLastIdetificationNumber(domainEntityName); lastIdentificationNumber.id += 1; await AddLastIdetificationNumber(lastIdentificationNumber); return(lastIdentificationNumber); }
public async Task <CompanyData> GetCompanyData() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); CompanyData companyData = null; FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query CompanyDataQuery = db.Collection("CompanyData"); CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken cancellationToken = cts.Token; QuerySnapshot CompanyDataQuerySnapshot; try { cts.CancelAfter(10000); CompanyDataQuerySnapshot = await CompanyDataQuery.GetSnapshotAsync(cancellationToken); } catch (OperationCanceledException) { Console.WriteLine("\r\nDownload canceled.\r\n"); return(null); } catch (AggregateException) { Console.WriteLine("\r\nDownload failed.\r\n"); return(null); } catch (Exception) { Console.WriteLine("\r\nDownload failed.\r\n"); return(null); } foreach (DocumentSnapshot documentSnapshot in CompanyDataQuerySnapshot.Documents) { Dictionary <string, object> companyDataDictionary = documentSnapshot.ToDictionary(); companyData = new CompanyData( companyDataDictionary["Address"].ToString(), companyDataDictionary["CompanyName"].ToString(), companyDataDictionary["Email"].ToString(), companyDataDictionary["PhoneNumber"].ToString(), companyDataDictionary["WebPageAddress"].ToString(), companyDataDictionary["CompanyLogo"].ToString(), companyDataDictionary["EmailSurename"].ToString(), StringEncoder.ReturnDecryptedPassword(companyDataDictionary["EmailPassword"].ToString()) ); } return(companyData); }
private async Task <LastIdentificationNumber> AddLastIdetificationNumber(LastIdentificationNumber lastIdentificationNumber) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); LastIdentificationNumber lastIdetificationNumber = new LastIdentificationNumber(); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", lastIdentificationNumber.id }, { "EntityName", lastIdentificationNumber.entityName } }; DocumentReference docRef = db.Collection("LastEntityIdentificationNumber").Document(lastIdentificationNumber.entityName + "Identification"); await docRef.SetAsync(user); return(lastIdetificationNumber); }
public async Task <bool> addParticipationFormat(string id, string value) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("ParticipationFormat").Document(id); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", id }, { "Value", value } }; await docRef.SetAsync(user); return(true); }
public async Task <bool> EditCompanyData(string address, string companyName, string email, string phoneNumber, string webPageAddress, string companyLogo, string emailSurename, string emailPassword) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); CancellationTokenSource cts = new CancellationTokenSource(); CancellationToken cancellationToken = cts.Token; DocumentReference docRef = db.Collection("CompanyData").Document("CompanyData"); string encodedEmailPassword = StringEncoder.ReturnEncryptedPassword(emailPassword); Dictionary <string, object> user = new Dictionary <string, object> { { "Address", address }, { "CompanyLogo", companyLogo }, { "CompanyName", companyName }, { "Email", email }, { "PhoneNumber", phoneNumber }, { "WebPageAddress", webPageAddress }, { "EmailSurename", emailSurename }, { "EmailPassword", encodedEmailPassword }, }; try { cts.CancelAfter(10000); await docRef.SetAsync(user, null, cancellationToken); } catch (OperationCanceledException) { Console.WriteLine("\r\nUpload canceled.\r\n"); return(false); } catch (AggregateException) { Console.WriteLine("\r\nUpload failed.\r\n"); return(false); } catch (Exception) { Console.WriteLine("\r\nUpload failed.\r\n"); return(false); } return(true); }
public async Task <bool> addMailTemplate(string id, string name, string subject, string body, bool is_Default) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("Mail_Template").Document("MailTemplate").Collection("MailTemplate").Document(id); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", id }, { "Name", name }, { "Subject", subject }, { "Body", body }, { "Is_Default", is_Default } }; await docRef.SetAsync(user); return(true); }
public async Task <bool> addParticipant(Participant participant) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("Participant").Document(participant.participantId); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", long.Parse(participant.participantId) }, { "EventId", participant.eventId }, { "FirstName", participant.firstName }, { "LastName", participant.lastName }, { "JobTitle", participant.jobTitle }, { "CompanyName", participant.companyName }, { "CompanyType", participant.companyType }, { "Email", participant.email }, { "PhoneNumber", participant.phoneNumber }, { "Country", participant.country }, { "ParticipantFormat", participant.participationFormat }, { "PaymentStatus", participant.paymentStatus }, { "Materials", participant.materials }, { "TicketBarcode", participant.ticketBarcode }, { "TicketSent", participant.ticketSent }, { "ParticipateEveningEvent", participant.participateEveningEvent }, { "ParticipateInDay1", participant.participateInDay1 }, { "ParticipateInDay2", participant.participateInDay2 }, { "ParticipateInDay3", participant.participateInDay3 }, { "ParticipateInDay4", participant.participateInDay4 }, { "CheckedInDay1", participant.checkedInDay1 }, { "CheckedInDay2", participant.checkedInDay2 }, { "CheckedInDay3", participant.checkedInDay3 }, { "CheckedInDay4", participant.checkedInDay4 }, { "RegistrationDate", participant.registrationDate.ToString() }, { "PaymentDate", participant.paymentDate.ToString() }, { "PaymentAmount", participant.paymentAmount.ToString() }, { "AdditionalPhoneNumber", participant.additionalPhoneNumber }, { "Comment", participant.comment } }; WriteResult result = await docRef.SetAsync(user); return(true); }
public async Task <bool> addUser(string username, string password, string mail, string phoneNumber, string name, string surename, long user_Id) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); DocumentReference docRef = db.Collection("System_User").Document(user_Id.ToString()); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", user_Id }, { "Mail", mail }, { "PhoneNumber", phoneNumber }, { "Name", name }, { "Surename", surename }, { "Password", password }, { "Username", username } }; await docRef.SetAsync(user); return(true); }
public async Task <List <ParticipationFormat> > getAllParticipationFormats() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); List <ParticipationFormat> participationFormats = new List <ParticipationFormat>(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query allParticipationFormatQuery = db.Collection("ParticipationFormat"); QuerySnapshot allParticipationFormatQuerySnapshot = await allParticipationFormatQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in allParticipationFormatQuerySnapshot.Documents) { Dictionary <string, object> participationFormat = documentSnapshot.ToDictionary(); ParticipationFormat ParticipationFormatEntity = new ParticipationFormat( participationFormat["Id"].ToString(), participationFormat["Value"].ToString() ); participationFormats.Add(ParticipationFormatEntity); } return(participationFormats); }
public async Task <List <EmailTemplateString> > getEmailTemplateStrings() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); List <EmailTemplateString> emailTemplateStrings = new List <EmailTemplateString>(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query allEmailTemplateStringsQuery = db.Collection("Mail_Template").Document("MailTemplateString").Collection("MailTemplateString"); QuerySnapshot allEmailTemplateStringsQuerySnapshot = await allEmailTemplateStringsQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in allEmailTemplateStringsQuerySnapshot.Documents) { Dictionary <string, object> EmailTemplateString = documentSnapshot.ToDictionary(); EmailTemplateString EmailTemplateStringEntity = new EmailTemplateString( EmailTemplateString["title"].ToString(), EmailTemplateString["dropString"].ToString() ); emailTemplateStrings.Add(EmailTemplateStringEntity); } return(emailTemplateStrings); }
public async Task <LastIdentificationNumber> getLastIdetificationNumber(string domainEntityName) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); long databaseId; string databaseEntityName; LastIdentificationNumber lastIdetificationNumber = new LastIdentificationNumber(); Query identificationNumberQuery = db.Collection("LastEntityIdentificationNumber").WhereEqualTo("EntityName", domainEntityName); QuerySnapshot identificationNumberQuerySnapshot = await identificationNumberQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in identificationNumberQuerySnapshot.Documents) { Console.WriteLine("Document data for {0} document:", documentSnapshot.Id); Dictionary <string, object> identificationNumberDocument = documentSnapshot.ToDictionary(); identificationNumberDocument.TryGetTypedValue("Id", out databaseId); identificationNumberDocument.TryGetTypedValue("EntityName", out databaseEntityName); lastIdetificationNumber.entityName = databaseEntityName; lastIdetificationNumber.id = databaseId; } return(lastIdetificationNumber); }
public async Task <List <EmailTemplate> > getAllMailTemplates() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); List <EmailTemplate> emailTemplates = new List <EmailTemplate>(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query allEmailTemplateQuery = db.Collection("Mail_Template").Document("MailTemplate").Collection("MailTemplate"); QuerySnapshot allEmailTemplateQuerySnapshot = await allEmailTemplateQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in allEmailTemplateQuerySnapshot.Documents) { Dictionary <string, object> EmailTemplate = documentSnapshot.ToDictionary(); EmailTemplate EmailTemplateEntity = new EmailTemplate( EmailTemplate["Id"].ToString(), EmailTemplate["Name"].ToString(), EmailTemplate["Subject"].ToString(), EmailTemplate["Body"].ToString(), bool.Parse(EmailTemplate["Is_Default"].ToString()) ); emailTemplates.Add(EmailTemplateEntity); } return(emailTemplates); }
public async Task <List <Participant> > getAllParticipants() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); List <Participant> allPartcipants = new List <Participant>(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query allParticipantsQuery = db.Collection("Participant"); QuerySnapshot allParticipantsQuerySnapshot = await allParticipantsQuery.GetSnapshotAsync(); DateTime registrationDate; DateTime paymentDate; int paymentAmount; string additionalPhoneNumber; string comment; foreach (DocumentSnapshot documentSnapshot in allParticipantsQuerySnapshot.Documents) { Console.WriteLine("Document data for {0} document:", documentSnapshot.Id); Dictionary <string, object> ParticipantValue = documentSnapshot.ToDictionary(); foreach (KeyValuePair <string, object> pair in ParticipantValue) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); } try { paymentDate = DateTime.Parse(ParticipantValue["PaymentDate"].ToString()); } catch (Exception) { paymentDate = DateHelper.setDateToMidnight(DateTime.Now); } try { registrationDate = DateTime.Parse(ParticipantValue["RegistrationDate"].ToString()); } catch (Exception) { registrationDate = DateHelper.setDateToMidnight(DateTime.Now); } try { paymentAmount = Int32.Parse(ParticipantValue["PaymentAmount"].ToString()); } catch (Exception) { paymentAmount = 0; } try { additionalPhoneNumber = ParticipantValue["AdditionalPhoneNumber"].ToString(); } catch (Exception) { additionalPhoneNumber = ""; } try { comment = ParticipantValue["Comment"].ToString(); } catch (Exception) { comment = ""; } Participant ParticipantEntity = new Participant( ParticipantValue["Id"].ToString(), ParticipantValue["EventId"].ToString(), ParticipantValue["FirstName"].ToString(), ParticipantValue["LastName"].ToString(), ParticipantValue["JobTitle"].ToString(), ParticipantValue["CompanyName"].ToString(), ParticipantValue["CompanyType"].ToString(), ParticipantValue["Email"].ToString(), ParticipantValue["PhoneNumber"].ToString(), ParticipantValue["Country"].ToString(), ParticipantValue["ParticipantFormat"].ToString(), ParticipantValue["PaymentStatus"].ToString(), Boolean.Parse(ParticipantValue["Materials"].ToString()), ParticipantValue["TicketBarcode"].ToString(), Boolean.Parse(ParticipantValue["TicketSent"].ToString()), Boolean.Parse(ParticipantValue["ParticipateEveningEvent"].ToString()), Boolean.Parse(ParticipantValue["ParticipateInDay1"].ToString()), Boolean.Parse(ParticipantValue["ParticipateInDay2"].ToString()), Boolean.Parse(ParticipantValue["ParticipateInDay3"].ToString()), Boolean.Parse(ParticipantValue["ParticipateInDay4"].ToString()), Boolean.Parse(ParticipantValue["CheckedInDay1"].ToString()), Boolean.Parse(ParticipantValue["CheckedInDay2"].ToString()), Boolean.Parse(ParticipantValue["CheckedInDay3"].ToString()), Boolean.Parse(ParticipantValue["CheckedInDay4"].ToString()), registrationDate, paymentDate, paymentAmount, additionalPhoneNumber, comment ); allPartcipants.Add(ParticipantEntity); Console.WriteLine(""); } return(allPartcipants); }
public async Task <bool> addEvent(long event_Id, string eventName, DateTime date_From, int eventLengthDays, DateTime day1Date, DateTime day2Date, DateTime day3Date, DateTime day4Date, string day1TimeFrom, string day1TimeTo, string day2TimeFrom, string day2TimeTo, string day3TimeFrom, string day3TimeTo, string day4TimeFrom, string day4TimeTo, string webPage, string venueName, string venueAddress, string eventStatus, string comment, bool useTemplate, string current_Mail_Template, string body, string subject) { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); string dateFromString = date_From.ToString(); string day1DateString = day1Date.ToString(); string day2DateString = day2Date.ToString(); string day3DateString = day3Date.ToString(); string day4DateString = day4Date.ToString(); DocumentReference docRef = db.Collection("Event").Document(event_Id.ToString()); Dictionary <string, object> user = new Dictionary <string, object> { { "Id", event_Id }, { "EventName", eventName }, { "DateFrom", dateFromString }, { "EventLengthDays", eventLengthDays }, { "DateDay1", day1DateString }, { "DateDay2", day2DateString }, { "DateDay3", day3DateString }, { "DateDay4", day4DateString }, { "Day1TimeFrom", day1TimeFrom }, { "Day1TimeTo", day1TimeTo }, { "Day2TimeFrom", day2TimeFrom }, { "Day2TimeTo", day2TimeTo }, { "Day3TimeFrom", day3TimeFrom }, { "Day3TimeTo", day3TimeTo }, { "Day4TimeFrom", day4TimeFrom }, { "Day4TimeTo", day4TimeTo }, { "WebPage", webPage }, { "VenueName", venueName }, { "VenueAdress", venueAddress }, { "EventStatus", eventStatus }, { "Comment", comment }, { "UseTemplate", useTemplate }, { "Current_Mail_Template", current_Mail_Template }, { "EmailBody", body }, { "EmailSubject", subject } }; try { await docRef.SetAsync(user); } catch (AggregateException) { return(false); } catch (Exception) { return(false); } return(true); }
public async Task <List <Event> > getAllEvents() { SetEnvironmentVariable.setFirestoreEnvironmentVariable(); List <Event> allEvents = new List <Event>(); FirestoreDb db = FirestoreDb.Create(GetConstant.FIRESTORE_ID); Query allEventsQuery = db.Collection("Event"); QuerySnapshot allEventsQuerySnapshot = await allEventsQuery.GetSnapshotAsync(); foreach (DocumentSnapshot documentSnapshot in allEventsQuerySnapshot.Documents) { Console.WriteLine("Document data for {0} document:", documentSnapshot.Id); Dictionary <string, object> eventValue = documentSnapshot.ToDictionary(); foreach (KeyValuePair <string, object> pair in eventValue) { Console.WriteLine("{0}: {1}", pair.Key, pair.Value); } object webPage = null; try { eventValue.TryGetValue("WebPage", out webPage).ToString(); } catch (ArgumentNullException) { Console.WriteLine("Web page got unsuccesfully"); }; string webPageString = ""; if (webPage != null) { webPageString = webPage.ToString(); } Event eventEntity = new Event( eventValue["Id"].ToString(), eventValue["EventName"].ToString(), DateTime.Parse(eventValue["DateFrom"].ToString()), Int32.Parse(eventValue["EventLengthDays"].ToString()), DateTime.Parse(eventValue["DateDay1"].ToString()), DateTime.Parse(eventValue["DateDay2"].ToString()), DateTime.Parse(eventValue["DateDay3"].ToString()), DateTime.Parse(eventValue["DateDay4"].ToString()), eventValue["Day1TimeFrom"].ToString(), eventValue["Day1TimeTo"].ToString(), eventValue["Day2TimeFrom"].ToString(), eventValue["Day2TimeTo"].ToString(), eventValue["Day3TimeFrom"].ToString(), eventValue["Day3TimeTo"].ToString(), eventValue["Day4TimeFrom"].ToString(), eventValue["Day4TimeTo"].ToString(), webPageString, eventValue["VenueName"].ToString(), eventValue["VenueAdress"].ToString(), eventValue["EventStatus"].ToString(), eventValue["Comment"].ToString(), Boolean.Parse(eventValue["UseTemplate"].ToString()), eventValue["Current_Mail_Template"].ToString(), eventValue["EmailBody"].ToString(), eventValue["EmailSubject"].ToString() ); allEvents.Add(eventEntity); Console.WriteLine(""); } if (allEvents.Count > 0) { allEvents = allEvents.OrderByDescending(ev => ev.date_From).ToList(); } return(allEvents); }
public string addImage(string imagePath, string imageId,string bucketName) { SetEnvironmentVariable.setGoogleCloudEnvironmentVariable(); string eventImageLink = ""; try { if (imagePath.Length != 0) { string sharedkeyFilePath = SetEnvironmentVariable.getGoogleCloudEnvironmentVariable(); GoogleCredential credential = null; using (var jsonStream = new FileStream(sharedkeyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read)) { credential = GoogleCredential.FromStream(jsonStream); } var storageClient = StorageClient.Create(credential); string[] spliters = { @"\" }; string filetoUpload = imagePath; string[] splitedString = imagePath.Split(spliters, StringSplitOptions.RemoveEmptyEntries); string fileName = splitedString[splitedString.Length - 1]; string[] spliters1 = { "." }; string[] splitedFileName = fileName.Split(spliters1, StringSplitOptions.RemoveEmptyEntries); string newFileName = ""; for (int i = 0; i < splitedFileName.Length; i++) { if (i != 0) { newFileName += "."; } newFileName += splitedFileName[i]; if (i == splitedFileName.Length - 2) { newFileName = newFileName + imageId; } } eventImageLink = newFileName; //check if object with name like this exists try { Google.Apis.Storage.v1.Data.Object GoogleFirestoreObject = storageClient.GetObject(bucketName, fileName); } catch (Exception ex) { Console.WriteLine("GoogleFirestoreObject does not exist"); } using (var fileStream = new FileStream(filetoUpload, FileMode.Open, FileAccess.Read, FileShare.Read)) { storageClient.UploadObject(bucketName, newFileName, "text/plain", fileStream); } Console.WriteLine("uploaded the file successfully"); } } catch (Exception ex) { throw ex; } SetEnvironmentVariable.setFirestoreEnvironmentVariable(); return eventImageLink; }