Ejemplo n.º 1
0
        //filter data from database in here
        public Response <List <Combi> > queryCombies(Filter filter)
        {
            List <CombiEntity.Combi> combies = null;

            if (filter != null)
            {
                combies = dbContext.Combies
                          .Where(x => x.Price >= filter.priceMore && x.Power >= filter.powerMore)
                          .ToList();
                if (filter.type != null)
                {
                    combies = combies.Where(x => x.Type.Contains(filter.type))
                              .ToList();
                }
            }
            else
            {
                combies = dbContext.Combies
                          .ToList();
            }

            if (combies != null)
            {
                return(success(Combi.fromEntity(combies)));
            }
            else
            {
                return(error <List <Combi> >(404, "Failed", null));
            }
        }
Ejemplo n.º 2
0
        public Response <List <Combi> > queryBest(Selection priority)
        {
            List <CombiEntity.Combi> entity = new List <CombiEntity.Combi>();

            for (int i = 0; i < 7; i++)
            {
                var c = dbContext.Combies.Where(e => !entity.Contains(e))
                        .MinBy(y => (y.Area - priority.square) >= 0 ? (y.Area - priority.square) : Int32.MaxValue);
                if (c != null)
                {
                    entity.Add(c);
                }
            }
            if (entity.Count > 0)
            {
                return(success(Combi.fromEntity(entity)));
            }
            else
            {
                return(error <List <Combi> >(404, "failed", null));
            }
        }