Exemplo n.º 1
0
        /// <summary>
        /// Adding user to db , check if user of given parameters exist
        /// and login and password are valid
        /// </summary>
        /// <param name="login"></param>
        /// <param name="password"></param>
        public async Task AddUserAsync(string login, string password)
        {
            var checkIfUserExist = await GetUserAsync(login, password);

            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
            {
                MessageBox.Show("Login or passowrd cannot be empty", "Notes Manager");
            }
            else if (login.Length < 2)
            {
                MessageBox.Show("Login is too short", "Notes Manager");
            }
            else if (password.Length < 5)
            {
                MessageBox.Show("Password length must be above 5 characters", "Notes Manager");
            }
            else if (!Equals(checkIfUserExist, null))
            {
                MessageBox.Show("User already exist!", "Notes Manager");
            }
            else
            {
                var user = new User(login, password);
                _noteDb.Users.Add(user);
                await _noteDb.SaveChangesAsync();

                MessageBox.Show("Register succesful", "NotesManager");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adding note to db
        /// </summary>
        /// <param name="note">adding entity</param>
        /// <returns>Id of added entity</returns>
        public async Task <int> AddAsync(Note note)
        {
            _noteDb.Notes.Add(note);
            await _noteDb.SaveChangesAsync();

            return(note.Id);
        }
Exemplo n.º 3
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            if (titleBlock.Text.Length < 1)
            {
                MessageBox.Show("Title too short");
                return;
            }
            NoteDb _dbContext = new NoteDb();
            var    note       = new Note(titleBlock.Text, contentBlock.Text);

            _dbContext.Notes.Add(note);
            await _dbContext.SaveChangesAsync();

            this.Hide();
        }