示例#1
0
        public async Task <IActionResult> LeaveGroup(DBModels.UserGroup userGroup)
        {
            var result = await userService.LeaveGroup(userGroup);

            if (result.IsSucess)
            {
                var returnObj = new { IsDeleted = result.IsDeleted, ErrorMessage = result.ErrorMessage };
                return(new OkObjectResult(returnObj));
            }
            return(NotFound(result.ErrorMessage));
        }
示例#2
0
        public async Task <IActionResult> JoinGroup(DBModels.UserGroup userGroup)
        {
            var result = await userService.JoinGroup(userGroup);

            if (result.IsSucess)
            {
                var returnObj = new { IsGroupFull = result.IsGroupFull, Message = result.Message };
                return(new OkObjectResult(returnObj));
            }
            else
            {
                return(NotFound(result.Message));
            }
        }
示例#3
0
        public async Task <(bool IsSucess, bool IsDeleted, string ErrorMessage)> LeaveGroup(DBModels.UserGroup group)
        {
            try
            {
                var userGroup = chatDbContext.UserGroups.Where(x => x.GroupId == group.GroupId && x.UserName == group.UserName).FirstOrDefault <DBModels.UserGroup>();
                if (userGroup != null)
                {
                    chatDbContext.UserGroups.Remove(userGroup);
                    await chatDbContext.SaveChangesAsync();

                    return(true, true, "Removed from Group SuccessFully!");
                }
                return(false, false, "Group Not Found");
            }
            catch (Exception ex)
            {
                return(false, false, ex.Message);
            }
        }
示例#4
0
        public async Task <(bool IsSucess, bool IsGroupFull, string Message)> JoinGroup(DBModels.UserGroup groupDetails)
        {
            try
            {
                var usersInGroups = await chatDbContext.UserGroups.Where(x => x.GroupId == groupDetails.GroupId).ToListAsync();

                string groupName = chatDbContext.Groups.SingleOrDefault(x => x.ID == groupDetails.GroupId)?.GroupName?.ToString();
                if (usersInGroups != null)
                {
                    if (usersInGroups.Count >= 20)
                    {
                        return(true, true, "Cannot Join the Group " + groupName + " as it is Full");
                    }
                    else
                    {
                        chatDbContext.UserGroups.Add(
                            new DBModels.UserGroup {
                            UserName = groupDetails.UserName, GroupId = groupDetails.GroupId
                        });
                        await chatDbContext.SaveChangesAsync();

                        return(true, false, "Joined " + groupName + " Successfully");
                    }
                }
                return(false, false, "Cannot Join the Group");
            }
            catch (Exception ex)
            {
                return(false, false, ex.Message);
            }
        }