public long Save(Group groupToSave)
        {
            using (var connection = OpenConnection())
            {
                // TODO: check transactions

                const string insertGroupQuery =
                    "INSERT INTO [Groups] (Name, Description, OwnerId)" +
                    "VALUES (@Name, @Description, @OwnerId);" +
                    "SELECT cast(scope_identity() as int)";

                var groupId = connection.Query<int>(insertGroupQuery, new
                {
                    groupToSave.Name,
                    groupToSave.Description,
                    groupToSave.OwnerId
                }).First();

                const string insertConnectionQuery =
                    "INSERT INTO [UsersGroups] (UserId, GroupId) VALUES(@UserId, @GroupId)";

                connection.Execute(insertConnectionQuery, new { UserId = groupToSave.OwnerId, GroupId = groupId });

                return groupId;
            }
        }
        public Group Save(Group group, string email)
        {
            var userId = _userRepository.GetUserByEmail(email).Id;

            group.OwnerId = userId;
            group.Id = _groupRepository.Save(group);

            return group;
        }
 public HttpResponseMessage Post(Group group)
 {
     return !User.Identity.IsAuthenticated ?
         Request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Please log in.") :
         Request.CreateResponse(HttpStatusCode.OK, _groupService.Save(group, User.Identity.Name));
 }