Example #1
0
        public async Task <IActionResult> PutCollectiveUser(int id, CollectiveUser collectiveUser)
        {
            if (id != collectiveUser.UserId)
            {
                return(BadRequest());
            }

            _context.Entry(collectiveUser).State = EntityState.Modified;

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

            return(NoContent());
        }
Example #2
0
        public async Task <ActionResult <CollectiveUser> > PostCollectiveUser(CollectiveUser collectiveUser)
        {
            _context.CollectiveUsers.Add(collectiveUser);
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                if (CollectiveUserExists(collectiveUser.UserId))
                {
                    return(Conflict());
                }
                else
                {
                    throw;
                }
            }

            return(CreatedAtAction("GetCollectiveUser", new { id = collectiveUser.UserId }, collectiveUser));
        }
Example #3
0
        /// <summary>Joins the collective asynchronous.</summary>
        /// <param name="collectiveid">The collectiveid.</param>
        /// <returns></returns>
        internal async Task <bool> JoinCollectiveAsync(int collectiveid)
        {
            var currentUser    = System.Text.Json.JsonSerializer.Deserialize <User>(ReadSetting("CurrentUser"));
            var collectiveuser = new CollectiveUser()
            {
                CollectiveId = collectiveid, UserId = currentUser.Id
            };
            var collectiveuserJson = JsonConvert.SerializeObject(collectiveuser);

#pragma warning disable CA2000 // Dispose objects before losing scope
            var userStringContent = new StringContent(collectiveuserJson, Encoding.UTF8, "application/json");
#pragma warning restore CA2000 // Dispose objects before losing scope
            if (await CrudHandler.JoinCollective(userStringContent, ReadSetting("AuthInfo")).ConfigureAwait(true))
            {
                userStringContent.Dispose();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        public async Task <ActionResult <CollectiveUser> > LeaveCollective(int collectiveid, int userid)
        {
            var collectiveUserList = await _context.CollectiveUsers.ToListAsync();

            CollectiveUser collectiveUser = new CollectiveUser();

            foreach (var item in collectiveUserList)
            {
                if (item.CollectiveId == collectiveid && item.UserId == userid)
                {
                    collectiveUser = item;
                    _context.CollectiveUsers.Remove(item);
                }
            }
            await _context.SaveChangesAsync();

            if (collectiveUser == null)
            {
                return(NotFound());
            }
            return(collectiveUser);
        }
 public static void AddMemberToCollective(CollectiveUser user, Collective c)
 {
     c.Members.Add(user);
 }