/// <summary>
        /// method to get the current capacity of a given date
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        private async Task <int> findCurrCapDate(DateTime dateTime)
        {
            int value = 0;
            //List<AssociateDto> assoc = await consumerHelper.ConsumeAssociatesFromAPI();
            //FIND THE APARTMENT

            List <HousingDataDto> dataList = await logicHelper.HousingDataGetAll();

            List <HousingDataDto> returnList = new List <HousingDataDto>();

            foreach (var item in dataList)
            {
                int b1 = (item.MoveInDate.CompareTo(dateTime));
                int b2 = (dateTime.CompareTo(item.MoveOutDate));

                if ((b1 == -1 || b1 == 0) && (b2 == 0 || b2 == 1))
                {
                    returnList.Add(item);
                }
            }

            List <ApartmentDto> aptDto = await logicHelper.ApartmentsGetAll();

            foreach (var item in returnList)
            {
                if (item.RoomID != null)
                {
                    ApartmentDto temp = aptDto.Find(id => id.RoomID.Equals(item.RoomID));
                    value += temp.CurrentCapacity;
                }
            }


            return(value);
        }
        /// <summary>
        /// this method removes an assocaite from a room and decrease the current capacity
        /// </summary>
        /// <param name="associate"></param>
        /// <returns></returns>
        public async Task <bool> RemoveAssocFromRoom(InsertAssociateDto associate)
        {
            //FIND THE ASSOCIATE FROM A LIST OF ASSOCIATES
            AssociateDto assoc = (await consumerHelper.ConsumeAssociatesFromAPI()).Find(id => id.AssociateID.Equals(associate.AssociateId));
            //FIND THE APARTMENT
            ApartmentDto aptDto = (await logicHelper.ApartmentsGetAll()).Find(id => id.RoomID.Equals(associate.RoomId));

            //FIND THE HousingData
            HousingDataDto data = (await logicHelper.HousingDataGetAll()).Find(id => id.AssociateID.Equals(associate.AssociateId));

            //update the status to 3  WHERE THREE MEANS TO DELETE
            data.StatusID = 3;
            if (aptDto.CurrentCapacity > 0)
            {
                aptDto.CurrentCapacity--;
            }
            else
            {
                return(false);
            }

            bool passed = await logicHelper.UpdateApartment(aptDto);

            bool passed3 = await logicHelper.UpdateHousingData(data);

            return(passed && passed3);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> LiversAdd(AddUserToFlateModel model)
        {
            string toReturn = "";
            IEnumerable <ApartmentDto> app = serviceAps.findAllWithFilter(apartment => apartment.ApartmentId == model.FlatId);

            int          a    = app.Count();
            ApartmentDto appp = app.First();
            IEnumerable <UserAppartmenDto> result = serviceUserAps.findAllWithFilter(apartment => apartment.ApartmentId == model.FlatId);

            if (appp.ApartmentSpace / (result.Count() + 1) > minMetersOnLiver)
            {
                UserAppartmenDto toSave = new UserAppartmenDto();
                toSave.ApartmentId = model.FlatId;
                toSave.UserId      = model.UserID;
                serviceUserAps.Create(toSave);
                toReturn = "saved";
                ViewData["CityWhichUserLooking"] = toReturn;
                return(View());
            }

            toReturn = "notEnogfPlace";

            ViewData["CityWhichUserLooking"] = toReturn;
            return(View());
        }
        public static ApartmentDto Map(Domain.Read.Models.ApartmentModel apartment)
        {
            var dto = new ApartmentDto
            {
                Id             = apartment.Id,
                ForRentalDates = apartment.ForRentalDates,
                AvailableDates = apartment.AvailableDates,
                CheckInTime    = apartment.CheckInTime,
                CheckOutTime   = apartment.CheckOutTime,
                ActivityState  = apartment.ActivityState,
                Rating         = apartment.Rating,
                Title          = apartment.Title,
                PricePerNight  = apartment.PricePerNight,
                ApartmentType  = apartment.ApartmentType,
                NumberOfGuests = apartment.NumberOfGuests,
                NumberOfRooms  = apartment.NumberOfRooms
            };

            dto.Amenities = apartment.Amenities.Select(a => Map <AmenityDto>(a)).ToList();
            dto.Images    = apartment.Images.Select(i => Map <ImageDto>(i)).ToList();
            dto.Comments  = apartment.Comments.Select(c => Map <CommentDto>(c)).ToList();
            dto.Location  = Map(apartment.Location);
            dto.HostId    = apartment.HostId;

            return(dto);
        }
Exemplo n.º 5
0
        public ApartmentDto Update(ApartmentDto tenant)
        {
            Apartment tenantToUpdate = Get(tenant.Id);

            _dbContext.Entry(tenantToUpdate).CurrentValues.SetValues(_mapper.Map <Apartment>(tenant));
            _dbContext.SaveChanges();
            return(_mapper.Map <ApartmentDto>(tenantToUpdate));
        }
        /// <summary>
        /// This method recieves an ApartmentDto model that we expect to delete based off of the primary key
        /// </summary>
        /// <param name="oldApartment"></param>
        /// <returns>Task<bool></returns>
        public async Task <bool> DeleteApartment(ApartmentDto oldApartment)
        {
            Apartment ApartmentVnM = new Apartment();

            //validate the incoming DTO first before converting into DAO
            //STILL NEED TO VALIDATE

            return(await graceService.DeleteApartmentAsync(ApartmentVnM.MapToDao(oldApartment)));
        }
Exemplo n.º 7
0
        public async Task AddApartmentAsync(ApartmentDto apartment)
        {
            var entry = apartment.ToEntry();
            await _baseInfoContext.ApartmentInfos.AddAsync(entry);

            await _baseInfoContext.SaveChangesAsync();

            apartment.ApartmentId = entry.ApartmentId;
        }
Exemplo n.º 8
0
        public ApartmentDto Add(ApartmentDto item)
        {
            Apartment tenant = _mapper.Map <Apartment>(item);

            _dbContext.Apartment.Add(tenant);
            _dbContext.SaveChanges();

            return(GetDto(tenant.Id));
        }
 public static ApartmentResponse ToModel(this ApartmentDto apartment)
 {
     return(new ApartmentResponse
     {
         ApartmentId = apartment.ApartmentId,
         Area = apartment.Area,
         CurrentOccupant = "NoOne",
         Number = apartment.Number
     });
 }
Exemplo n.º 10
0
 public static ApartmentInfo ToEntry(this ApartmentDto apartment)
 {
     return(new ApartmentInfo
     {
         ApartmentId = apartment.ApartmentId,
         Area = apartment.Area,
         BuildingId = apartment.BuildingId,
         Number = apartment.Number
     });
 }
Exemplo n.º 11
0
        public IActionResult Single(int id)
        {
            ApartmentDto apartment = _apartmentRepository.GetDto(id);

            if (apartment == null)
            {
                return(NotFound());
            }

            return(Ok(apartment));
        }
Exemplo n.º 12
0
        public IActionResult Remove(int id)
        {
            ApartmentDto apartment = _apartmentRepository.GetDto(id);

            if (apartment == null)
            {
                return(NotFound());
            }

            _apartmentRepository.Delete(id);
            return(NoContent());
        }
        /// <summary>
        /// this method inserts an assocaite into a room and increase the current capacity
        /// </summary>
        /// <param name="associate"></param>
        /// <returns></returns>
        public async Task <bool> InsertAssociateToRoom(InsertAssociateDto associate)
        {
            //FIND THE ASSOCIATE FROM A LIST OF ASSOCIATES
            AssociateDto assoc = (await consumerHelper.ConsumeAssociatesFromAPI()).Find(id => id.AssociateID.Equals(associate.AssociateId));
            //FIND THE APARTMENT
            ApartmentDto aptDto = (await logicHelper.ApartmentsGetAll()).Find(id => id.RoomID.Equals(associate.RoomId));

            List <HousingDataDto> tt = await logicHelper.HousingDataGetAll();

            HousingDataDto data = new HousingDataDto()
            {
                AssociateID = assoc.AssociateID,
                MoveInDate  = associate.MoveInDate,
                MoveOutDate = associate.MoveOutDate,
                RoomID      = associate.RoomId,
                StatusID    = 1
            };

            string RoomsGender = "Male";

            if (aptDto.GenderID == 2) //Female on gender table
            {
                RoomsGender = "Female";
            }

            if ((aptDto.CurrentCapacity < aptDto.MaxCapacity) && (RoomsGender == assoc.Gender))
            {
                aptDto.CurrentCapacity++;
            }
            else
            {
                return(false);
            }
            bool passed  = false;
            bool passed2 = false;

            if (tt.Exists(id => id.AssociateID.Equals(data.AssociateID)))
            {
                passed2 = await logicHelper.UpdateHousingData(data);
            }
            else
            {
                passed2 = await logicHelper.AddHousingData(data);
            }

            if (passed2)
            {
                passed = await logicHelper.UpdateApartment(aptDto);
            }


            return(passed && passed2);
        }
Exemplo n.º 14
0
        public virtual IActionResult GetItem([FromBody] int id)
        {
            ApartmentDto dto = service.GetById(id);

            if (dto == null)
            {
                return(BadRequest());
            }

            ApartmentModel model = mapper.Map <ApartmentModel>(dto);

            return(Ok(model));
        }
Exemplo n.º 15
0
 public async Task <HttpResponseMessage> Get([FromUri] ApartmentDto apartment)
 {
     try
     {
         var Response = Request.CreateResponse(HttpStatusCode.OK, await traineeConsumer.ConsumeAssociatesFromAPI());
         log.Info("GetAssociates Get Successsful");
         return(Response);
     }
     catch (Exception ex)
     {
         LogHelper.SendError(log, ex);
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
        public async Task <IActionResult> CreateApartment(ApartmentDto apartmentDto)
        {
            if (apartmentDto.Title == null || apartmentDto.NbOfRooms == null || apartmentDto.Address == null)
            {
                return(BadRequest("Missing field"));
            }

            var apartmentToCreate = new Apartment();

            var createdApartment = await _repo.CreateApartment(apartmentToCreate, apartmentDto.Title,
                                                               (int)apartmentDto.NbOfRooms, apartmentDto.Address);

            return(StatusCode(201));
        }
Exemplo n.º 17
0
        /// <summary>
        /// this method inserts a new apartment by calling on the soap service.
        /// The "graceService.insert" returns a bool value so we just return
        /// that since it depends on its pass or fail
        /// </summary>
        /// <param name="newApt"></param>
        /// <returns></returns>
        public async Task <bool> AddApartment(ApartmentDto newApt)
        {
            try
            {
                Apartment apartmentVnM = new Apartment();

                //validate the incoming DTO first before converting into DAO
                //STILL NEED TO VALIDATE

                return(await graceService.InsertApartmentAsync(apartmentVnM.MapToDao(newApt)));
            }
            catch (Exception)
            {
                return(false);
            }
        }
Exemplo n.º 18
0
        public IActionResult Add([FromBody] ApartmentDto apartment)
        {
            if (apartment == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApartmentDto apartmentAdded = _apartmentRepository.Add(apartment);

            return(Ok(apartmentAdded));
        }
Exemplo n.º 19
0
        public virtual IActionResult UpdateItem([FromBody] ApartmentModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApartmentDto dto = mapper.Map <ApartmentDto>(model);

            service.Update(dto);

            return(Ok());
        }
 /// <summary>
 /// put method for apartment
 /// </summary>
 /// <param name="apartment"></param>
 /// <returns></returns>
 public async Task <HttpResponseMessage> Put([FromBody] ApartmentDto apartment)
 {
     try
     {
         if (await logicHelper.UpdateApartment(apartment))
         {
             var Response1 = Request.CreateResponse(HttpStatusCode.OK, "successful update");
             log.Info("Apartment Put Successful");
             return(Response1);
         }
         var Response2 = Request.CreateResponse(HttpStatusCode.BadRequest, "failed to update");
         log.Info("Apartment Put Unsuccessful");
         return(Response2);
     }
     catch (Exception ex)
     {
         LogHelper.SendError(log, ex);
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 21
0
        public void Apartment_Map_To_Entry()
        {
            ApartmentDto otdto = new ApartmentDto
            {
                BuildingId  = 1,
                Area        = 29,
                ApartmentId = 4,
                Number      = 34
            };
            ApartmentInfo ow = otdto.ToEntry();

            bool check = false;

            if (otdto.Number == ow.Number && otdto.BuildingId == ow.BuildingId &&
                otdto.ApartmentId == ow.ApartmentId && ow.Area == otdto.Area)
            {
                check = true;
            }
            Assert.IsTrue(check);
        }
 /// <summary>
 /// post method for inserting a new apartment
 /// </summary>
 /// <param name="newApartmentDto"></param>
 /// <returns></returns>
 public async Task <HttpResponseMessage> Post([FromBody] ApartmentDto newApartmentDto)
 {
     try
     {
         newApartmentDto.ActiveBit       = true;
         newApartmentDto.CurrentCapacity = 0;
         if (await logicHelper.AddApartment(newApartmentDto))
         {
             var Response1 = Request.CreateResponse(HttpStatusCode.OK, "successful insert");
             log.Info("Apartment Post Successful");
             return(Response1);
         }
         var Response2 = Request.CreateResponse(HttpStatusCode.BadRequest, "failed to insert");
         log.Info("Apartment Post Unsuccessful");
         return(Response2);
     }
     catch (Exception ex)
     {
         LogHelper.SendError(log, ex);
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
 }
Exemplo n.º 23
0
        public IActionResult Update(int id, [FromBody] ApartmentDto apartment)
        {
            var apartmentToCheck = _apartmentRepository.Get(id);

            if (apartmentToCheck == null)
            {
                return(NotFound());
            }

            if (id != apartment.Id)
            {
                return(BadRequest("Ids do not match"));
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApartmentDto updatedapartment = _apartmentRepository.Update(apartment);

            return(Ok(updatedapartment));
        }
Exemplo n.º 24
0
        private async Task ValidateApartment(ApartmentDto apartment)
        {
            const int MIN_AREA_FOR_UNIT = 20;

            if (apartment.Area < MIN_AREA_FOR_UNIT)
            {
                throw new ValidationException(ErrorCodes.Invalid_Area, $"Area of an Apartment can not be smaller than 20");
            }
            var building = await _buildingrepository.GetBuildingAsync(apartment.BuildingId);

            if (building.NumberOfUnits < apartment.Number)
            {
                throw new ValidationException(ErrorCodes.Max_Apartment_Number, $"Number Unit should not be greater than counts of building aparment");
            }

            foreach (var c in await _buildingrepository.GetBuildingApartments(building.BuildingId))
            {
                if (c.Number == apartment.Number)
                {
                    throw new ValidationException(ErrorCodes.Invalid_Apartment_Number, $"This apartment Number Already exists");
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// This method maps from a ApartmentDto to a ApartmentDao
        /// </summary>
        /// <param name="apt"></param>
        /// <returns>ApartmentDao</returns>
        public ApartmentDao MapToDao(ApartmentDto apt)
        {
            var mapper = apartmentMapper.CreateMapper();

            return(mapper.Map <ApartmentDao>(apt));
        }
Exemplo n.º 26
0
        public async Task AddAppartment(ApartmentDto apartment)
        {
            await ValidateApartment(apartment);

            await _buildingrepository.AddApartmentAsync(apartment);
        }
Exemplo n.º 27
0
 public async Task AddApartmentAsync(ApartmentDto apartment)
 {
     apartment.ApartmentId = _apartments.Max(a => a.ApartmentId) + 1;
     _apartments.Add(apartment);
 }