public RoomViewModel([NotNull] ProjectAccommodation entity, RoomTypeViewModel owner) { if (entity.ProjectId == 0 || entity.Id == 0) { throw new ArgumentException("Entity must be valid object"); } Id = entity.Id; Name = entity.Name; ProjectId = entity.ProjectId; RoomTypeId = entity.AccommodationTypeId; Capacity = entity.ProjectAccommodationType?.Capacity ?? 0; // Extracting list of requests associated with this room Requests = owner.Requests.Where(r => { var result = r.RoomId == Id; if (result) { Occupancy += r.Persons; r.Room = this; } return(result); }).ToList(); CanManageRooms = owner.CanManageRooms; CanAssignRooms = owner.CanAssignRooms; }
private async Task <T> CreateRoomEmail <T>(ProjectAccommodation room, Claim[] changed) where T : RoomEmailBase, new() { return(new T() { Changed = changed, Initiator = await GetCurrentUser(), ProjectName = room.Project.ProjectName, Recipients = room.GetSubscriptions().ToList(), Room = room, Text = new MarkdownString(), }); }
private async Task UnOccupyRoomImpl(ProjectAccommodation room, IReadOnlyCollection <AccommodationRequest> accommodationRequests) { room.Project.RequestMasterAccess(CurrentUserId, acl => acl.CanSetPlayersAccommodations); foreach (var request in accommodationRequests) { request.AccommodationId = null; request.Accommodation = null; } await UnitOfWork.SaveChangesAsync(); await EmailService.Email( await CreateRoomEmail <UnOccupyRoomEmail>(room, accommodationRequests.SelectMany(x => x.Subjects).ToArray())); }
public static IEnumerable <User> GetSubscriptions(this ProjectAccommodation room) { return(room.Inhabitants.SelectMany(i => i.Subjects).SelectMany(claim => claim.GetSubscriptions(subs => subs.AccommodationChange, Enumerable.Empty <User>()).Distinct().ToList())); }
public JoinRpgInsufficientRoomSpaceException(ProjectAccommodation entity) : base(entity, "There is no space in room") { }
public RoomIsOccupiedException(ProjectAccommodation entity) : base(entity, "Cannot peforrm this operation on occupied room.") { }
public static int GetRoomFreeSpace(this ProjectAccommodation room) => room.ProjectAccommodationType.Capacity - room.GetAllInhabitants().Count();
public static bool IsOccupied(this ProjectAccommodation pa) => pa.Inhabitants.Any();
public static IEnumerable <Claim> GetAllInhabitants(this ProjectAccommodation room) => room.Inhabitants.SelectMany(i => i.Subjects);
public static bool IsOccupied(this ProjectAccommodation pa) { return(pa.Inhabitants.Any()); }