// metoda care transforma un string in data si timp // DateTime-ul returnat reprezinta data nasteri a userilor private DateTime GetUserBirthDate(string text) { if (Validate.ValidateString(text)) { try { string[] birthDateValues = text.Split(','); int year = int.Parse(birthDateValues[0]); int month = int.Parse(birthDateValues[1]); int day = int.Parse(birthDateValues[2]); return(new DateTime(year, month, day)); } catch { StandardMessages.FakeBirthDate(); GetUserBirthDate(UserCommand.Read()); return(DateTime.Now); } } else { StandardMessages.FakeBirthDate(); GetUserBirthDate(UserCommand.Read()); return(DateTime.Now); } }
// metoda folosita pentru conectarea in aplicatie public override void LogIn() { // se citesc de la tastatura emailul si parola StandardMessages.Email(); string email = GetUserEmail(UserCommand.Read()); StandardMessages.Password(); string password = GetUserValue(UserCommand.Read()); bool successConnected = false; // se parcurge lista cu useri AllUsers // daca este gasit un user cu emailul si parola identice cu cele citite de la tastatura // proprietatea IsLogin a userului primeste valoarea true foreach (var user in AllUsers) { if (user.Email == email && user.Password == password) { user.IsLogin = true; successConnected = true; UserConnected = user.FirstName; } if (user.Email != email && user.Password != password && user.IsLogin) { user.IsLogin = false; } } if (successConnected) { StandardMessages.SuccessLogIn(UserConnected); } else { StandardMessages.ErrorLogIn(); } }
// metoda care returneaza un mail citit de la tastatura, dupa ce este validat private string GetUserEmail(string text) { if (Validate.EmailValidate(text)) { return(text.Trim()); } else { StandardMessages.FakeEmail(); GetUserEmail(UserCommand.Read()); return(bool.FalseString); } }
// metoda returneaza un string citit de la tastatura, dupa ce a fost validat private string GetUserValue(string text, string user = null) { if (Validate.ValidateString(text)) { return(text.Trim()); } else { StandardMessages.FakeValue(user); GetUserValue(UserCommand.Read()); return(bool.FalseString); } }
// metoda folosita pentru adaugarea unei postari noi // o postare noua poate fi adaugata doar daca userul este conectat public override void AddPost() { if (UserConnected == null) { OnUserNotConnected(); return; } StandardMessages.AddPost(UserConnected); string post = GetUserValue(UserCommand.Read(), UserConnected); NewPostIsAdded(postId, Factory.CreatePost(postId++, UserConnected, post)); OnNewMessage(UserConnected); }
// metoda utilizata pentru crearea unui cont de utilizator public override void CreateAccount() { // se citesc de la tastatura valori pentru fiecare proprietate din User si se valideaza StandardMessages.FirstName(); string firstName = GetUserValue(UserCommand.Read()); StandardMessages.LastName(); string lastName = GetUserValue(UserCommand.Read()); StandardMessages.Email(); string email = GetUserEmail(UserCommand.Read()); StandardMessages.Password(); string password = GetUserValue(UserCommand.Read()); StandardMessages.BirthDate(); DateTime birthDate = GetUserBirthDate(UserCommand.Read()); // este adaugat un user nou in lista AllUsers AllUsers.Add(Factory.CreateUser(userId++, birthDate, firstName, lastName, email, password)); }