本文整理汇总了C#中IDocumentSession.UpdatePlayerInvitation方法的典型用法代码示例。如果您正苦于以下问题:C# IDocumentSession.UpdatePlayerInvitation方法的具体用法?C# IDocumentSession.UpdatePlayerInvitation怎么用?C# IDocumentSession.UpdatePlayerInvitation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocumentSession
的用法示例。
在下文中一共展示了IDocumentSession.UpdatePlayerInvitation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PostPlayer
public static object PostPlayer(
NancyContext context,
IDocumentSession documentSession,
IMailSender mailSender,
string roomSlug,
string invitationCode,
string characterName,
string characterAvatarUrl)
{
context.Ensure("context");
documentSession.Ensure("documentSession");
mailSender.Ensure("mailSender");
if (string.IsNullOrEmpty(roomSlug))
return 404;
if (!context.IsSignedUp())
return 403;
var room = documentSession.GetRoomBySlug(roomSlug);
if (room == null)
return 404;
var currentMember = context.GetCurrentMember(documentSession);
Debug.Assert(currentMember != null, "`requireSignedUp()` should ensure a current member.");
var errors = new List<string>();
errors.AddRange(fn.ValidateRequired("Invitation code", invitationCode));
var playerInvitation = documentSession.GetPlayerInvitationByCode(invitationCode);
if (playerInvitation == null)
errors.Add("The invitation code is not valid.");
if (playerInvitation != null && playerInvitation.Used)
errors.Add("The invitation code has already been used.");
errors.AddRange(fn.ValidateRequired("Character Name", characterName));
errors.AddRange(fn.ValidateLength("Character Name", characterName, 64));
errors.AddRange(fn.ValidateFormat("Character Name", characterName, new Regex("^[a-z][a-z0-9 .'-]+$", RegexOptions.IgnoreCase)));
if (!string.IsNullOrEmpty(characterAvatarUrl))
errors.AddRange(fn.ValidateUrl("Avatar URL", characterAvatarUrl));
var existingPlayer = room.Players.FirstOrDefault(p => p.CharacterName.Equals(characterName, StringComparison.OrdinalIgnoreCase));
if (existingPlayer != null)
errors.Add(Strings.NotAvailable("character name", characterName));
if (errors.Count > 0)
return context.ModelWithStatus(new AcceptInvitationFormResponse(room, invitationCode, characterName, characterAvatarUrl, errors), 400);
var player = new Player
{
CharacterAvatarUrl = characterAvatarUrl,
CharacterName = characterName,
MemberAlias = currentMember.Alias,
MemberId = currentMember.Id,
MemberEmailAddress = currentMember.EmailAddress,
RoomId = room.Id
};
room.Players.Add(player);
documentSession.UpdatePlayerInvitation(playerInvitation.Id, used: true);
string text = Strings.Format("{0} joined the room as {1}.", player.MemberAlias, player.CharacterName);
documentSession.CreatePost(mailSender, room.Id, currentMember.Id, null, null, "system", text);
return context.Redirect(Paths.Room(room.Slug));
}