/// <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(); } }