/// <summary> /// Validate values of person data /// </summary> /// <param name="values">List of strings to validate</param> /// <returns>True if values are valid, in other case false</returns> public bool validateValues(ParamsForRegister values) { bool res = true; new List <String> { values.name, values.surname, values.username, values.password, values.group, values.zal, values.ticket }.ForEach(value => { if (String.IsNullOrWhiteSpace(value)) { res = false; } }); if (values.password != values.passwordRepeat) { res = false; } long temp; if (!long.TryParse(values.ticket, out temp)) { res = false; } if (!long.TryParse(values.zal, out temp)) { res = false; } return(res); }
/// <summary> /// Register user with adding one to database /// </summary> /// <param name="name">Name of new user</param> /// <param name="surname">Surname of new user</param> /// <param name="zal">Student ticket number of new user</param> /// <param name="username">Username of new user</param> /// <param name="password">Password of new user</param> /// <returns></returns> public bool registerUser(ParamsForRegister values) { Model.Person person = new Model.Person { Name = values.name, Surname = values.surname, Password = values.password, Photo = userPhoto, Username = values.username }; Model.Student student = new Model.Student { TicketNumber = long.Parse(values.ticket), ReportCard = long.Parse(values.zal), PersonID = values.username, GroupID = values.group }; if (service.LoadLogInPersonAsync(values.username) == null) { service.CreatePersonAsync(person).Wait(); service.CreateStudentAsync(student).Wait(); return(true); } else { return(false); } }