Example #1
0
        public async Task <City> GetByUniqueIdentifiers(string[] propertyNames, City entity)
        {
            DbCommand <City> selectWithUniqueAttributes = new SelectWithAttributeValuesCommand <City>(propertyNames);
            List <City>      cities = await ServiceHelper <City> .ExecuteSelectCommand(selectWithUniqueAttributes, entity);

            return(cities.Count == 0 ? null : cities[0]);
        }
        public async Task <List <Address> > GetAllInCity(string cityName)
        {
            City city = await cityService.GetByUniqueIdentifiers(new string[] { "Name" }, new City()
            {
                Name = cityName
            });

            DbCommand <AddressCity> command       = new SelectWithAttributeValuesCommand <AddressCity>(new string[] { "IdCity" });
            List <AddressCity>      addressCities = await ServiceHelper <AddressCity> .ExecuteSelectCommand(command, new AddressCity()
            {
                IdCity = city.IdCity
            });

            List <Address> addresses = new List <Address>();

            foreach (var x in addressCities)
            {
                Address address = await addressService.GetByPrimaryKey(new Address()
                {
                    IdAddress = x.IdAddress
                });

                addresses.Add(address);
            }
            return(addresses);
        }
        public async Task <List <Answer> > GetAnswers(int idQuestion)
        {
            List <Answer> answers = new List <Answer>();
            Answer        tmp     = new Answer()
            {
                IdQuestion = idQuestion
            };
            DbCommand <Answer> command = new SelectWithAttributeValuesCommand <Answer>(new string[] { "IdQuestion" });

            answers = await ServiceHelper <Answer> .ExecuteSelectCommand(command, tmp);

            return(answers);
        }
Example #4
0
        public async Task <int> GetCountInOneCity(string cityName, EventFilter filter, int?idCategory = null)
        {
            City city = await cityService.GetByUniqueIdentifiers(new string[] { "Name" }, new City()
            {
                Name = cityName
            });

            Event tmp = new Event()
            {
                IdCity = city.IdCity,
            };

            if (filter == EventFilter.CATEGORY)
            {
                tmp.IdCategory = idCategory.Value;
                DbCommand <Event> scalarCommand = new CountCommand <Event>(new string[] { "IdCity", "IdCategory" }, tmp);
                return(Convert.ToInt32(await ServiceHelper <Event> .ExecuteScalarCommand(scalarCommand)));
            }
            else
            {
                DbCommand <Event> selectCommand = new SelectWithAttributeValuesCommand <Event>(new string[] { "IdCity" });
                List <Event>      events        = await ServiceHelper <Event> .ExecuteSelectCommand(selectCommand, tmp);

                if (filter == EventFilter.PRESENT)
                {
                    return(events.Where(x => x.ScheduledOn.Date == DateTime.Now.Date).ToList().Count);
                }
                else if (filter == EventFilter.FUTURE)
                {
                    return(events.Where(x => x.ScheduledOn > DateTime.Now).ToList().Count);
                }
                else
                {
                    return(events.Count);
                }
            }
        }
Example #5
0
        public async Task <List <Event> > GetRangeInOneCityWithFilter(int offset, int limit, string cityName, EventFilter filter, int?idCategory = null, string orderByAttribute = null, string order = "asc")
        {
            City city = await cityService.GetByUniqueIdentifiers(new string[] { "Name" }, new City()
            {
                Name = cityName
            });

            Event tmp = new Event()
            {
                IdCity = city.IdCity,
            };

            if (filter == EventFilter.CATEGORY)
            {
                if (idCategory.HasValue)
                {
                    tmp.IdCategory = idCategory.Value;
                }
                DbCommand <Event> selectCommand = new SelectWithRangeAndFilterCommand <Event>(offset, limit, orderByAttribute ?? "Name", new string[] { "IdCity", "IdCategory" }, tmp, order);
                return(await ServiceHelper <Event> .ExecuteSelectCommand(selectCommand));
            }
            else
            {
                DbCommand <Event> selectCommand = new SelectWithAttributeValuesCommand <Event>(new string[] { "IdCity" }, orderByAttribute ?? "Name", order);
                List <Event>      events        = await ServiceHelper <Event> .ExecuteSelectCommand(selectCommand, tmp);

                if (filter == EventFilter.PRESENT)
                {
                    events = events.Where(x => x.ScheduledOn.Date == DateTime.Now.Date).ToList();
                }
                else if (filter == EventFilter.FUTURE)
                {
                    events = events.Where(x => x.ScheduledOn > DateTime.Now).ToList();
                }
                return(events.Skip(offset).Take(limit).ToList());;
            }
        }