/// <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); }
/// <summary> /// this method returns a list of all the associates consumed from felice that are inside a particular room /// </summary> /// <param name="associate"></param> /// <returns></returns> public async Task <List <AssociateDto> > AssociatesGetByApartment(InsertAssociateDto associate) { List <AssociateDto> assDto = await consumerHelper.ConsumeAssociatesFromAPI(); //find all housingDatas with a given room id List <HousingDataDto> dataDto = (await logicHelper.HousingDataGetAll()).FindAll(x => x.RoomID.Equals(associate.RoomId)); //now the above list has housingDatas with the same roomid and with different AssociateIds so we will return a list of all the //associate dtos were thier id is equal to the housing data dataDto.RemoveAll(x => x.StatusID.Equals(3)); List <AssociateDto> returnList = new List <AssociateDto>(); foreach (var item in assDto) { if (dataDto.Exists(x => x.AssociateID.Equals(item.AssociateID))) { returnList.Add(item); } } return(returnList); }
/// <summary> /// not implemented yet but we want this to change associate to a different room /// NOTE: This method may need to be removed as it's overall functionality does not seem needed in the long run /// </summary> /// <param name="associate"></param> /// <returns></returns> public HttpResponseMessage Put([FromBody] InsertAssociateDto associate) { //if (await associateHelper.ChangeAssocToDifferentRoom(associate)) //{ // return Request.CreateResponse(HttpStatusCode.OK, "successfully moved associate to another apartment room"); //} log.Info("Associate Put Unsuccessful"); return(Request.CreateResponse(HttpStatusCode.BadRequest, "failed to move associate to another apartment room")); }
/// <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); }
/// <summary> /// this method deletes assocaite from a room /// </summary> /// <param name="associate"></param> /// <returns></returns> public async Task <HttpResponseMessage> Delete([FromBody] InsertAssociateDto associate) { try { if (await associateHelper.RemoveAssocFromRoom(associate)) { var Response1 = Request.CreateResponse(HttpStatusCode.OK, "successfully removed associate from apartment room"); log.Info("Associate Delete Successful"); return(Response1); } var Response2 = Request.CreateResponse(HttpStatusCode.BadRequest, "failed to remove assocaiate from apartment room"); log.Info("Associate Delete Unsuccessful"); return(Response2); } catch (Exception ex) { LogHelper.SendError(log, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest, "failed to remove assocaiate from apartment room")); } }
/// <summary> /// http post to post associate into room /// </summary> /// <param name="associate"></param> /// <returns></returns> public async Task <HttpResponseMessage> Post([FromBody] InsertAssociateDto associate) { try { if (await associateHelper.InsertAssociateToRoom(associate)) { var theResponseByAp = Request.CreateResponse(HttpStatusCode.OK, "Successfully registered associate into a apartment room"); log.Info("Associate Post Successful"); return(theResponseByAp); } var theResponse2 = Request.CreateResponse(HttpStatusCode.BadRequest, "failed to insert associate into a apartment room"); log.Info("Associate Post Unsuccessful"); return(theResponse2); } catch (Exception ex) { LogHelper.SendError(log, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest, "failed to insert associate into a apartment room")); } }
/// <summary> /// http get method if -1 is passed in we get associates who are roomless otherwise we return all associate /// that are in the given apartment /// </summary> /// <param name="associate"></param> /// <returns></returns> public async Task <HttpResponseMessage> Get([FromUri] InsertAssociateDto associate) { try { if (associate.AssociateId.Equals(-1)) { var theResponseRmlss = Request.CreateResponse(HttpStatusCode.OK, await associateHelper.AssociatesGetRoomless()); log.Info("Associate Get Successful"); return(theResponseRmlss); } var theResponseByAp = Request.CreateResponse(HttpStatusCode.OK, await associateHelper.AssociatesGetByApartment(associate)); log.Info("Associate Get Successful"); return(theResponseByAp); } catch (Exception ex) { LogHelper.SendError(log, ex); return(Request.CreateResponse(HttpStatusCode.BadRequest)); } }