public static List <SuggestionDto> GetMatchingSuggestions(RequestDto requestDto) { return(DAL.Match.GetMatchingSuggestions(requestDto).ConvertAll <SuggestionDto>(s => { return Suggestion.ToDTO(s); })); }
public Suggestion HandleEfficientCapacity(Building building) { double percentage = 0, sumOfTrash = 0; DateTime lastThreeMonths = DateTime.Now.AddDays(-90); // Three months back List <Bin> buildingBins; List <WasteTransferLog> buildingWasteTransferLog; try { buildingBins = this.db.Bins.Where(x => x.BuildingId == building.BuildingId).ToList(); //All the bins in the building buildingWasteTransferLog = this.db.WasteTransferLogs .Where(x => x.CreatedDate >= lastThreeMonths && buildingBins.FindIndex(f => f.BinId == x.BinId) != -1).ToList(); //buildingWasteTransferLog from the last three months, in the building foreach (WasteTransferLog wtl in buildingWasteTransferLog) { sumOfTrash += wtl.TransferedCapacity; } double sumMaxCapacity = this.db.LUT_BinType .Where(x => buildingBins.FindIndex(f => f.BinTypeId == x.BinTypeId) != -1) .Select(g => g.Capacity).Sum(); double fullSumMaxCapacity = sumMaxCapacity * 12 * building.LUT_Weekdays.ToList().Count; //100% full each cleanup(three months = 12 weeks) //sumMax*12*number of cleanup each week percentage = (sumOfTrash * 100) / fullSumMaxCapacity; //Calculate percentage if (percentage >= 80) //More than 80% === add/replace bin { if (building.LUT_Weekdays.ToList().Count == 1) { int dayId = building.LUT_Weekdays.Select(x => x.WeekdayId).SingleOrDefault(); int addDayId = this.db.LUT_Weekdays.Where(x => x.WeekdayId == (dayId + 3) % 6) .Select(x => x.WeekdayId).SingleOrDefault(); Suggestion suj = new Suggestion() { suggestionAction = SuggestionAction.add, suggestionEntity = SuggestionEntity.Day, entityIds = new List <int>() { addDayId } }; return(suj); } else { double desparea = 0; //BinTrashDisposalArea foreach (Bin bin in buildingBins) //For each bin in the building we add its BinTrashDisposalArea { desparea += (double)(this.db.LUT_BinType .Where(x => x.BinTypeId == bin.BinTypeId) .Select(g => g.BinTrashDisposalArea).SingleOrDefault()); } double remainingDisposalArea = building.TrashDisposalArea - desparea; List <LUT_BinType> binTypeList = this.db.LUT_BinType.ToList(); binTypeList.OrderByDescending(x => x.BinTrashDisposalArea); //Sort bintype by BinTrashDisposalArea(descending) foreach (LUT_BinType binType in binTypeList) { if (binType.BinTrashDisposalArea <= remainingDisposalArea) { Suggestion suj = new Suggestion() { suggestionAction = SuggestionAction.add, suggestionEntity = SuggestionEntity.Bin, entityIds = new List <int>() { binType.BinTypeId } }; return(suj); //Retrun the largest bin that fit } } //if we are here we have to replace bin List <int> binTypeId = this.db.LUT_BinType .Where(x => buildingBins.FindIndex(f => f.BinTypeId == x.BinTypeId) != -1) .Select(x => x.BinTypeId).ToList(); List <List <int> > allCombos = GetAllCombos(binTypeId); //List of all the combinations allCombos.OrderBy(x => x.Count); //Sort by numbers of bin double currentDisposalArea, currentMaxCapacity; List <int> bestCombo = new List <int>(); foreach (List <int> combo in allCombos) //Go over allCombos { currentDisposalArea = 0; currentMaxCapacity = 0; foreach (int bint in combo) { currentMaxCapacity += this.db.LUT_BinType.Where(x => x.BinTypeId == bint) //Calculating currentMaxCapacity .Select(x => x.Capacity).SingleOrDefault(); currentDisposalArea += (double)this.db.LUT_BinType.Where(x => x.BinTypeId == bint) //Calculating currentDisposalArea .Select(x => x.BinTrashDisposalArea).SingleOrDefault(); bestCombo.Add(bint); //Creating the return string } if (currentDisposalArea <= desparea && currentMaxCapacity > sumMaxCapacity) //Check if this combo is good === combo.disposalArea <= building.disposalArea { // && combo.maxCapacity > previousBuildingCombo.maxCapacity Suggestion suj = new Suggestion() { suggestionAction = SuggestionAction.add, suggestionEntity = SuggestionEntity.Bin, entityIds = bestCombo }; return(suj); //Best combo } } return(null); //Cann't add (Should not happen) } } else if (percentage <= 60) //Less than 60% === remove/replace bin { if (building.LUT_Weekdays.ToList().Count == 2) { int dayId = building.LUT_Weekdays.LastOrDefault().WeekdayId; Suggestion suj = new Suggestion() { suggestionAction = SuggestionAction.remove, suggestionEntity = SuggestionEntity.Day, entityIds = new List <int>() { dayId } }; return(suj); } else //remove the smallest bin { List <LUT_BinType> buildingBinTypeList = this.db.LUT_BinType .Where(x => buildingBins.FindIndex(f => f.BinTypeId == x.BinTypeId) != -1).ToList(); buildingBinTypeList.OrderBy(x => x.Capacity); int binId = buildingBinTypeList.First().BinTypeId; Suggestion suj = new Suggestion() { suggestionAction = SuggestionAction.remove, suggestionEntity = SuggestionEntity.Bin, entityIds = new List <int>() { binId } }; return(suj); } } else //(Should not happen) { return(null); } } catch (Exception ex) { throw ErrorHandler.Handle(ex, this); } }
/// <summary> /// קבלת הצעה לפי קוד /// </summary> /// <param name="id"></param> /// <returns></returns> public static SuggestionDto GetSuggestion(int id) { return(Suggestion.ToDTO(DAL.ManageSuggestion.GetSuggestion(id))); }
/// <summary> /// עדכון הצעה /// </summary> /// <param name="suggestionDto"></param> /// <returns></returns> public static SuggestionDto UpdateSuggestion(SuggestionDto suggestionDto) { return(Suggestion.ToDTO(DAL.ManageSuggestion.UpdateSuggestion(Suggestion.ToDAL(suggestionDto)))); }
public static bool DeleteSuggestion(SuggestionDto suggestionDto) { return(DAL.ManageSuggestion.DeleteSuggestion(Suggestion.ToDAL(suggestionDto))); }