public ClaimListItemViewModel([NotNull]
                                      Claim claim,
                                      int currentUserId)
        {
            if (claim == null)
            {
                throw new ArgumentNullException(nameof(claim));
            }
            var lastComment = claim.CommentDiscussion.Comments.Where(c => c.IsVisibleToPlayer)
                              .OrderByDescending(c => c.CommentId).FirstOrDefault();

            ClaimId = claim.ClaimId;

            ClaimFullStatusView = new ClaimFullStatusView(claim, new AccessArguments(claim, currentUserId));
            Name   = claim.Name;
            Player = claim.Player;

            UpdateDate          = lastComment?.LastEditTime ?? claim.CreateDate;
            CreateDate          = claim.CreateDate;
            Responsible         = claim.ResponsibleMasterUser;
            LastModifiedBy      = lastComment?.Author ?? claim.Player;
            UnreadCommentsCount = claim.CommentDiscussion.GetUnreadCount(currentUserId);

            ProjectId   = claim.ProjectId;
            ProjectName = claim.Project.ProjectName;
            Fields      = claim.GetFields();
            FeePaid     = claim.ClaimBalance();
            FeeDue      = claim.ClaimFeeDue();

            PreferentialFeeUser = claim.PreferentialFeeUser;


            AccomodationType = claim.AccommodationRequest?.AccommodationType.Name;
            RoomName         = claim.AccommodationRequest?.Accommodation?.Name;
        }
        public ClaimViewModel(User currentUser,
                              Claim claim,
                              IEnumerable <PluginOperationData <IPrintCardPluginOperation> > pluginOperationDatas,
                              IReadOnlyCollection <PlotElement> plotElements,
                              IUriService uriService,
                              IEnumerable <ProjectAccommodationType> availableAccommodationTypes = null,
                              IEnumerable <AccommodationRequest> accommodationRequests           = null,
                              IEnumerable <AccommodationPotentialNeighbors> potentialNeighbors   = null,
                              IEnumerable <AccommodationInvite> incomingInvite = null,
                              IEnumerable <AccommodationInvite> outgoingInvite = null)
        {
            ClaimId             = claim.ClaimId;
            CommentDiscussionId = claim.CommentDiscussionId;
            RootComments        = claim.CommentDiscussion.ToCommentTreeViewModel(currentUser.UserId);
            HasMasterAccess     = claim.HasMasterAccess(currentUser.UserId);
            CanManageThisClaim  = claim.HasAccess(currentUser.UserId,
                                                  acl => acl.CanManageClaims,
                                                  ExtraAccessReason.ResponsibleMaster);
            CanChangeRooms = claim.HasAccess(currentUser.UserId,
                                             acl => acl.CanSetPlayersAccommodations,
                                             ExtraAccessReason.PlayerOrResponsible);
            IsMyClaim                   = claim.PlayerUserId == currentUser.UserId;
            Player                      = claim.Player;
            ProjectId                   = claim.ProjectId;
            ProjectName                 = claim.Project.ProjectName;
            Status                      = new ClaimFullStatusView(claim, new AccessArguments(claim, currentUser.UserId));
            CharacterGroupId            = claim.CharacterGroupId;
            GroupName                   = claim.Group?.CharacterGroupName;
            CharacterId                 = claim.CharacterId;
            CharacterActive             = claim.Character?.IsActive;
            CharacterAutoCreated        = claim.Character?.AutoCreated;
            AvailableAccommodationTypes = availableAccommodationTypes?.Where(a =>
                                                                             a.IsPlayerSelectable || a.Id == claim.AccommodationRequest?.AccommodationTypeId ||
                                                                             claim.HasMasterAccess(currentUser.UserId)).ToList();
            PotentialNeighbors               = potentialNeighbors;
            AccommodationRequest             = claim.AccommodationRequest;
            IncomingInvite                   = incomingInvite;
            OutgoingInvite                   = outgoingInvite;
            OtherClaimsForThisCharacterCount = claim.IsApproved
              ? 0
              : claim.OtherClaimsForThisCharacter().Count();
            HasOtherApprovedClaim = !claim.IsApproved &&
                                    claim.OtherClaimsForThisCharacter().Any(c => c.IsApproved);
            Data = new CharacterTreeBuilder(claim.Project.RootGroup, currentUser.UserId).Generate();
            OtherClaimsFromThisPlayerCount     =
                OtherClaimsFromThisPlayerCount =
                    claim.IsApproved || claim.Project.Details.EnableManyCharacters
                      ? 0
                      : claim.OtherPendingClaimsForThisPlayer().Count();
            Masters =
                claim.Project.GetMasterListViewModel()
                .Union(new MasterListItemViewModel()
            {
                Id = "-1", Name = "Нет"
            });
            ResponsibleMasterId = claim.ResponsibleMasterUserId ?? -1;
            ResponsibleMaster   = claim.ResponsibleMasterUser;
            Fields     = new CustomFieldsViewModel(currentUser.UserId, claim);
            Navigation =
                CharacterNavigationViewModel.FromClaim(claim,
                                                       currentUser.UserId,
                                                       CharacterNavigationPage.Claim);
            ClaimFee      = new ClaimFeeViewModel(claim, this, currentUser.UserId);
            Problems      = claim.GetProblems().Select(p => new ProblemViewModel(p)).ToList();
            PlayerDetails = new UserProfileDetailsViewModel(claim.Player,
                                                            (AccessReason)claim.Player.GetProfileAccess(currentUser));
            PrintPlugins         = pluginOperationDatas.Select(PluginOperationDescriptionViewModel.Create);
            ProjectActive        = claim.Project.Active;
            CheckInStarted       = claim.Project.Details.CheckInProgress;
            CheckInModuleEnabled = claim.Project.Details.EnableCheckInModule;
            Validator            = new ClaimCheckInValidator(claim);

            AccommodationEnabled = claim.Project.Details.EnableAccommodation;

            if (claim.HasAccess(currentUser.UserId,
                                acl => acl.CanManageMoney, ExtraAccessReason.Player))
            {
                //Finance admins can create any payment. User also can create any payment, but it will be moderated
                PaymentTypes = claim.Project.ActivePaymentTypes;
            }
            else
            {
                //All other master can create only payment from user to himself.
                PaymentTypes =
                    claim.Project.ActivePaymentTypes.Where(pt => pt.UserId == currentUser.UserId);
            }


            if (claim.Character != null)
            {
                ParentGroups = new CharacterParentGroupsViewModel(claim.Character,
                                                                  claim.HasMasterAccess(currentUser.UserId));
            }

            if (claim.IsApproved && claim.Character != null)
            {
                var readOnlyList = claim.Character.GetOrderedPlots(plotElements);
                Plot = PlotDisplayViewModel.Published(readOnlyList,
                                                      currentUser.UserId,
                                                      claim.Character,
                                                      uriService);
            }
            else
            {
                Plot = PlotDisplayViewModel.Empty();
            }
        }
 public static bool CanHaveSecondRole(this ClaimFullStatusView status) =>
 status.ClaimStatus == ClaimStatusView.CheckedIn;
 public static bool IsAlreadyApproved(this ClaimFullStatusView status) =>
 status.ClaimStatus == ClaimStatusView.Approved ||
 status.ClaimStatus == ClaimStatusView.CheckedIn;
 public static bool IsActive(this ClaimFullStatusView status) =>
 ((Claim.Status)status.ClaimStatus).IsActive();
        // TODO A lot of checks should be unified to Domain (like CanChangeTo)

        public static bool CanMove(this ClaimFullStatusView status)
        => status.ClaimStatus == ClaimStatusView.AddedByUser ||
        status.ClaimStatus == ClaimStatusView.Approved ||
        status.ClaimStatus == ClaimStatusView.Discussed ||
        status.ClaimStatus == ClaimStatusView.OnHold;
 public static bool CanChangeTo(this ClaimFullStatusView fromStatus,
                                ClaimStatusView targetStatus)
 => ((Claim.Status)fromStatus.ClaimStatus).CanChangeTo((Claim.Status)targetStatus);