示例#1
0
        public ResponseModel <string> GetById(string token)
        {
            var resp = new ResponseModel <string>();

            try
            {
                var groupInvite = GroupInvitationsRepository.GetByToken(token);

                if (groupInvite != null)
                {
                    var user = UserRepository.GetUserByEmail(groupInvite.Email);

                    if (user == null)
                    {
                        throw new Exception("User not exist");
                    }

                    var model = new UserGroup()
                    {
                        IdUser  = user.Id,
                        IdGroup = groupInvite.GroupId
                    };

                    if (UserGroupRepository.Exist(model.IdUser, model.IdGroup))
                    {
                        throw new Exception("User already exist in the group");
                    }

                    if (UserGroupRepository.Insert(model))
                    {
                        resp.Data        = model.Id.ToString();
                        resp.Status      = 200;
                        resp.Description = "OK";
                    }
                    else
                    {
                        throw new Exception("Not inserted");
                    }
                    resp.Data        = "OK";
                    resp.Status      = 200;
                    resp.Description = "OK";
                }
                else
                {
                    resp.Status      = 200;
                    resp.Data        = null;
                    resp.Description = "GroupInvitations not found";
                }
            }
            catch (Exception ex)
            {
                resp.Status      = 500;
                resp.Description = $"Error: {ex.Message}";
                resp.Data        = null;
            }

            return(resp);
        }