예제 #1
0
        private async Task ValidateOwnerTenantAsync(OwnerTenantDto ownertenant)
        {
            if (ownertenant.To < ownertenant.From)
            {
                throw new ValidationException(ErrorCodes.Invalid_Entrence_Time, $"Date entrance should not be greater than Exit Time ");
            }

            var allCurrentOwners = await _buildingManager.GetAllCurrrentOwnerOfApartment(ownertenant.ApartmentId);

            foreach (var ot in allCurrentOwners)
            {
                if (ot.IsOwner == ownertenant.IsOwner && ot.From < ownertenant.To && ot.To >= ownertenant.From)
                {
                    throw new ValidationException(ErrorCodes.Apartment_Is_Taken, $"This apartment Is occupied");
                }
            }

            if (!ownertenant.IsOwner && ownertenant.OccupantCount < 1)
            {
                throw new ValidationException(ErrorCodes.OccupantCount_Error, $"The counts of the occupant should not be smaller than 1");
            }
        }
        public async Task <IActionResult> GetAllOwnerTenatsOfApartment(int apartmentId)
        {
            var ownerTenats = await buildingManager.GetAllCurrrentOwnerOfApartment(apartmentId);

            var apartment = await buildingManager.GetApartment(apartmentId);

            var apartmentModels = new ApartmentOwnerTenantResponse
            {
                Apartment = apartment,
                Owner     = ownerTenats.FirstOrDefault(c => c.IsOwner),
                Tenant    = ownerTenats.FirstOrDefault(c => !c.IsOwner),
            };

            return(Ok(apartmentModels.WrapResponse(Request.Path)));
        }