예제 #1
0
 /// <summary>
 /// Constructor
 /// If the group is edited it fills text boxes and lists with proper data.
 /// </summary>
 /// <param name="group">loaded group </param>
 /// <param name="edit">indicates if we edit a group or user creates new one</param>
 public CreateGroupForm(GroupsViewModel group, bool edit)
 {
     InitializeComponent();
     currGroup = group;
     this.edit = edit;
     //usersDataView.UserDeletedRow += RemoveUser;
     if (edit)
     {
         tbTitle.Text = currGroup.name;
         tbDesc.Text = currGroup.description;
         UpdateSource();
     }
     else
     {
         usersBindingSource.Add(Globals.CurrentUser);
     }
     //usersDataView.CellDoubleClick += SeeUsersProfile;
 }
예제 #2
0
        /// <summary>
        /// Constructor fills text boxes, labels and lists wit the proper data.
        /// </summary>
        /// <param name="group"></param>
        /// <param name="isAdmin"></param>
        public GroupViewForm(GroupsViewModel group, bool isAdmin = false)
        {
            InitializeComponent();

            this.currGroup = group;
            this.isAdmin = isAdmin;

            lblTitle.Text = group.name;
            this.Name = group.name;
            tbDesc.Text = group.description;

            yearsGridView.CellDoubleClick += SeeYearDetails;

            FindUser();

            if (isAdmin)
            {
                btnAddYear.Enabled = true;
                btnLeave.Text = "Delete group";
            }
            UpdateYearsSource();
        }
예제 #3
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();
            }

        }
예제 #4
0
        public async Task<IHttpActionResult> PutGroups(int id, GroupsViewModel groups)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            if (id != groups.id)
            {
                return BadRequest();
            }

            var groupToEdit = await db.Groups.FirstOrDefaultAsync(g => g.id == id);

            groupToEdit.name = groups.name;
            groupToEdit.description= groups.description;
            //groupToEdit.created_at = groups.created_at; //if any error occured delete uncomment these 2 lines
            //groupToEdit.owner_id = groups.owner_id;

            db.Entry(groupToEdit).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GroupsExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return StatusCode(HttpStatusCode.NoContent);
        }
예제 #5
0
        public async Task<IHttpActionResult> PostGroups(GroupsViewModel groups)
        {
            Groups newGroup = new Groups()
            {
                name = groups.name,
                created_at = groups.created_at,
                description = groups.description,
                owner_id = groups.owner_id,
            };

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            db.Groups.Add(newGroup);
            await db.SaveChangesAsync();

            var retGroup = Mapper.Map<GroupsViewModel>(newGroup);
            return CreatedAtRoute("DefaultApi", new { id = newGroup.id }, retGroup);
        }
예제 #6
0
 /// <summary>
 /// Constructor taking group to which year is assigned.
 /// </summary>
 /// <param name="group"></param>
 public YearForm(GroupsViewModel group) : this()
 {
     currGroup = group;
 }
예제 #7
0
        /// <summary>
        /// Synchronizes current group with actual group from database.
        /// </summary>
        /// <returns></returns>
        public async Task SyncGroup()
        {
            HttpGroupsRepository repo = new HttpGroupsRepository();

            currGroup = await repo.GetOne(currGroup.id);
        }