public AccRequestViewModel(AccommodationRequest entity) { Id = entity.Id; ProjectId = entity.ProjectId; AccommodationTypeId = entity.AccommodationTypeId; RoomId = entity.AccommodationId ?? 0; Participants = entity.Subjects.Select(c => new RequestParticipantViewModel(c)).ToList(); FeeTotal = Participants.Sum(p => p.FeeTotal); FeeToPay = Participants.Sum(p => p.FeeToPay); FeeToPay = FeeToPay > 0 ? FeeToPay : 0; // if FeeToPay < 0 we have overpaid int percent = FeeToPay == 0 ? 100 : (FeeToPay == FeeTotal ? 0 : 100 * FeeToPay / FeeTotal); PaymentStatusCssClass = percent == 100 ? @"success" : (percent >= 25 ? @"warning" : @"danger"); }
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 async Task <AccommodationRequest> SetAccommodationType(int projectId, int claimId, int roomTypeId) { //todo set first state to Unanswered var claim = await ClaimsRepository.GetClaim(projectId, claimId).ConfigureAwait(false); claim = claim.RequestAccess(CurrentUserId, acl => acl.CanSetPlayersAccommodations, claim?.ClaimStatus == Claim.Status.Approved ? ExtraAccessReason.PlayerOrResponsible : ExtraAccessReason.None); // Player cannot change accommodation type if already checked in if (claim.AccommodationRequest?.AccommodationTypeId == roomTypeId) { return(claim.AccommodationRequest); } var newType = await UnitOfWork.GetDbSet <ProjectAccommodationType>().FindAsync(roomTypeId) .ConfigureAwait(false); if (newType == null) { throw new JoinRpgEntityNotFoundException(roomTypeId, nameof(ProjectAccommodationType)); } var email = EmailHelpers.CreateFieldsEmail(claim, s => s.AccommodationChange, await GetCurrentUser(), new FieldWithPreviousAndNewValue[] { }, new Dictionary <string, PreviousAndNewValue>() { { "Тип поселения", //TODO[Localize] new PreviousAndNewValue(newType.Name, claim.AccommodationRequest?.AccommodationType.Name) }, }); var leaveEmail = await ConsiderLeavingRoom(claim); var accommodationRequest = new AccommodationRequest { ProjectId = projectId, Subjects = new List <Claim> { claim }, AccommodationTypeId = roomTypeId, IsAccepted = AccommodationRequest.InviteState.Accepted, }; UnitOfWork .GetDbSet <AccommodationRequest>() .Add(accommodationRequest); await UnitOfWork.SaveChangesAsync().ConfigureAwait(false); await EmailService.Email(email); if (leaveEmail != null) { await EmailService.Email(leaveEmail); } return(accommodationRequest); }
public static int GetAbstractRoomFreeSpace(this AccommodationRequest request) { return(request.AccommodationType.Capacity - request.Subjects.Count); }