Example #1
0
        /// <summary>
        /// Saves and validates provided data.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void SaveChangesClick(object sender, EventArgs e)
        {
            IStringValidator validator = new Validator();
            if (!validator.IsNotEmpty(tbTitle.Text))
            {
                MessageBox.Show("Title can not be empty!");
                return;
            }

            HttpGroupsRepository groupRepo = new HttpGroupsRepository();

            currGroup.description = tbDesc.Text;
            if (!validator.IsNotEmpty(tbTitle.Text))
            {
                MessageBox.Show("Group name can't be empty!","Error!",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                return;
            }
            currGroup.name = tbTitle.Text;

            if (edit)
            {
                await UpdateUsers();
                await groupRepo.EditOne(currGroup);

                await Globals.UpdateCurrentUser();
                this.Close();
            }
            else
            {
                var detailRepo = new HttpGroupDetailsRepository();

                var newGroup = new GroupsViewModel()
                {
                    created_at = DateTime.Now,
                    GroupDetails = currGroup.GroupDetails,
                    name = currGroup.name,
                    owner_id = Globals.CurrentUser.id,
                    description = currGroup.description
                };

                GroupsViewModel retGroup = await groupRepo.AddOne(newGroup); //we need it to get created id
                
                currGroup.id = retGroup.id; 
                //adding users
                await UpdateUsers();

                await Globals.UpdateCurrentUser();

                this.Close();
            }

        }
Example #2
0
        /// <summary>
        /// Saves the edited or new Subject.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
 
        private async void btnSubjectSave_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            this.Enabled = false;

            Validator validator = new Validator();
            subjectLocal.name = txtSubjectName.Text;
            subjectLocal.teacher_mail = txtSubjectEmail.Text;

            // Validating the mail
            if (validator.IsNotEmpty(subjectLocal.teacher_mail))
            {
                if (!(validator.isValidMail(subjectLocal.teacher_mail)))
                {
                    MessageBox.Show("Incorrect email. Needs to be in form: \" [email protected] \"", "Error!",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            if (!validator.IsNotEmpty(txtSubjectName.Text)) {
                MessageBox.Show("Name of the subject can not be empty.", "Error!",
                            MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            subjectLocal.sub_desc = txtSubjectDesc.Text;

            try
            {
                // Depending on whether adding or editing a Subject differen action performed.
                if (edit)
                {
                    await subjects.EditOne(subjectLocal);
                    DialogResult dialogResult = MessageBox.Show("Changes saved successfuly.", "Subject", MessageBoxButtons.OK);
                    this.Close();
                }
                else
                {
                    await subjects.AddOne(subjectLocal);
                    DialogResult dialogResult = MessageBox.Show("Subject added successfuly.", "Subject", MessageBoxButtons.OK);
                    this.Close();
                }
            }
            catch (Exception exception) {
                MessageBox.Show(exception.Message,
                        "Error",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
            }
            this.Cursor = Cursors.Default;
            this.Enabled = true;

        }
Example #3
0
        /// <summary>
        /// Adds user to binding source and also validates the added user.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void AddUserClick(object sender, EventArgs e)
        {
            HttpUsersRepository repo = new HttpUsersRepository();
            IStringValidator validator = new Validator();
            string username = tbUser.Text;
            if (!validator.IsNotEmpty(username))
            {
                MessageBox.Show("Provide username!", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            //if (username == Globals.CurrentUser.username)
            //{
            //    MessageBox.Show("You can not add yourself to group! (you are already in it)");
            //    return;
            //}
            if (usersBindingSource.Cast<UsersViewModel>().Any(user => user.username == username))
            {
                MessageBox.Show("You have already added such a user!");
                return;
            }

            if (await repo.UserExists(username))
            {
                var user = await repo.GetUser(username);
                usersBindingSource.Add(user);
            }
            else
            {
                MessageBox.Show("There is no such a user!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }