Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 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(),
     });
 }
Ejemplo n.º 3
0
        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()));
        }
Ejemplo n.º 4
0
 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()));
 }
Ejemplo n.º 5
0
 public JoinRpgInsufficientRoomSpaceException(ProjectAccommodation entity) : base(entity, "There is no space in room")
 {
 }
Ejemplo n.º 6
0
 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);
Ejemplo n.º 10
0
 public static bool IsOccupied(this ProjectAccommodation pa)
 {
     return(pa.Inhabitants.Any());
 }