/// <summary> /// Register process. /// </summary> /// <returns>True if user enteres correct input.</returns> private static bool RegisterProcess() { string uniqueCode = GetRandomCode(); IOService.Print(Resources.inputEmail); string userInputEmail = Console.ReadLine(); if (!CheckBackOrExit(userInputEmail)) return false; IOService.Print(Resources.passwordInput); string userInputPassword = Console.ReadLine(); if (!CheckBackOrExit(userInputPassword)) return false; List<ToDoItem> toDoList = new List<ToDoItem>(); User user = new User(userInputEmail, userInputPassword, uniqueCode, toDoList); if (!UserRepository.AddUser(user)) { Console.WriteLine("The user already exsits. Press any key to go back to startup screen."); Console.ReadKey(); return false; } try { IEmailService sendEmail = new EmailService(); MailMessage mail = new MailMessage(EmailSettings.email, userInputEmail, "Activation code for registering", "Please enter this activation code for further registration:" + uniqueCode); sendEmail.SendEmail(mail); } catch (Exception) { IOService.Print(Resources.EmailResources.sendEmailFail); Console.ReadKey(); return false; } IOService.Print(Resources.activationCodeInput); bool isValid = false; do { string enterActivationCode = Console.ReadLine(); if (!CheckBackOrExit(enterActivationCode)) { isValid = false; } else if (!enterActivationCode.Equals(uniqueCode)) { IOService.Print(Resources.wrongCommand + enterActivationCode); isValid = false; } else { isValid = true; } } while (!isValid); return true; }
/// <summary> /// Removes item from the list. /// </summary> /// <returns>True if successfully removed from the list.</returns> private static bool RemoveToDo() { User logedInUser = UserRepository.GetLogedInUser(); IOService.Print(Resources.removeToDo); int indexOfToDoInt = 0; bool isValid = true; do { string indexOfToDo = Console.ReadLine(); if (!CheckBackOrExit(indexOfToDo)) return false; else if (!Int32.TryParse(indexOfToDo, out indexOfToDoInt)) { IOService.Print(Resources.wrongCommand); isValid = false; } else if (indexOfToDoInt - 1 > logedInUser.TodoList.Count || indexOfToDoInt < 1) { IOService.Print(Resources.wrongCommand); isValid = false; } else { isValid = true; } } while (!isValid); IOService.Print(Resources.EmailResources.removedTaskEmail); IEmailService sendEmail = new EmailService(); MailMessage mail = new MailMessage(EmailSettings.email, logedInUser.Email, "Removed task", "To do task removed:\n" + logedInUser.TodoList[indexOfToDoInt - 1].Description); try { sendEmail.SendEmail(mail); } catch (Exception) { IOService.Print(Resources.EmailResources.sendEmailFail); Console.ReadKey(); return false; } indexOfToDoInt -= 1; UserRepository.RemoveToDo(indexOfToDoInt); return true; }
/// <summary> /// Adds item to the list. /// </summary> /// <returns>True if successfully added to the list.</returns> private static bool AddToList() { User logedInUser = UserRepository.GetLogedInUser(); IOService.Print(Resources.inputDescriptionOfToDo, 1); string descriptionOfTheToDo = Console.ReadLine(); if (!CheckBackOrExit(descriptionOfTheToDo)) return false; IOService.Print(Resources.inputDueDateOfToDo); string dueDate = Console.ReadLine(); if (!CheckBackOrExit(dueDate)) return false; IOService.Print(Resources.EmailResources.taskAddedEmail); UserRepository.AddToDo(new ToDoItem(descriptionOfTheToDo, dueDate, false)); IEmailService sendEmail = new EmailService(); MailMessage mail = new MailMessage(EmailSettings.email, logedInUser.Email, "To do task", "To do description:\n" + descriptionOfTheToDo + "Due date of to do:\n" + dueDate); try { sendEmail.SendEmail(mail); } catch (Exception) { IOService.Print(Resources.EmailResources.sendEmailFail); Console.ReadKey(); return false; } return true; }