public List <Service> Get(ServiceFilter filter) { try { Console.Clear(); Console.WriteLine("Repository: SERVICE\n\n"); string cmd = "Select * from Service "; List <string> wcmd = new List <string>(); if (!String.IsNullOrEmpty(filter.name)) { wcmd.Add("name LIKE '" + filter.name + "%'"); } if (!String.IsNullOrEmpty(filter.description)) { wcmd.Add("description LIKE '" + filter.description + "%'"); } if (filter.price.HasValue) { wcmd.Add("price = " + Helper.ToMyString(filter.price.ToString())); } if (filter.priceLowerThan.HasValue) { wcmd.Add("price < " + Helper.ToMyString(filter.priceLowerThan.ToString())); } if (filter.priceUpperThan.HasValue) { wcmd.Add("price > " + Helper.ToMyString(filter.priceUpperThan.ToString())); } if (wcmd.Count() > 0) { cmd += "where " + string.Join(" AND ", wcmd.ToArray()); } List <Service> serviceList = new List <Service>(); DbDataReader reader = ExecuteReader(cmd); while (reader.Read()) { Service service = new Service(); service.service_id = (long)reader["service_id"]; service.name = (string)reader["name"]; service.description = (string)reader["description"]; var p = reader["price"]; if (p != null) { service.price = Convert.ToDouble(p); } serviceList.Add(service); } return(serviceList); } catch (Exception e) { Console.WriteLine("Error " + e.ToString()); Console.ReadKey(); return(new List <Service>()); } }
public async Task <IActionResult> PostSearches(ServiceFilter servicefilter) => Ok((await this.repo.GetAll()) .Where(x => (servicefilter.CategoryId == null || x.Category == servicefilter.CategoryId) && (servicefilter.IsConfigured == null || (servicefilter.IsConfigured.Value && x.Attributes?.Any() == true) || (!servicefilter.IsConfigured.Value && !x.Attributes?.Any() != true))) .OrderBy(x => x.Name));
public async Task <ObservableCollection <SingleService> > GetSingleServices(ServiceFilter filter) { filter.IsCourse = false; var ret = new ObservableCollection <SingleService>(); foreach (var c in await Post <ServiceFilter, ObservableCollection <DtoService> >("GetServices", filter)) { ret.Add(ServiceConverter.DtoToViewModelSingleService(c)); } return(ret); }
/// <summary> /// Method returning filtered courses /// </summary> /// <param name="filter">Filter to select specific courses</param> /// <returns>IEnumerable of DtoService</returns> public async Task <IEnumerable <DtoService> > GetServices(ServiceFilter filter = null) { var ret = new ObservableCollection <DtoService>(); try { using (var data = Context) { if (filter == null) { foreach ( var course in await data.Service.Where(s => s.ServiceType.isCourse).Take(TakeTop).ToListAsync()) { ret.Add(ServiceConverter.DataAccessToDto(course)); } } else { var services = await data.Service .Where (s => s.ServiceType.isCourse == filter.IsCourse && (string.IsNullOrEmpty(filter.Customer) || s.Customer.Any( c => c.name.Contains(filter.Customer) || c.surname.Contains(filter.Customer))) && (string.IsNullOrEmpty(filter.Instructor) || s.Employee.name.Contains(filter.Instructor) || s.Employee.surname.Contains(filter.Instructor)) && (filter.ServiceTypeId == null || s.ServiceType.id == filter.ServiceTypeId) && (filter.SportId == null || s.ServiceType.sportTypeID == filter.SportId) && (string.IsNullOrEmpty(filter.CustomerEmail) || s.Customer.Any(c => c.email == filter.CustomerEmail)) ) .Take(TakeTop).ToListAsync(); foreach (var course in services) { ret.Add(ServiceConverter.DataAccessToDto(course)); } } } } catch (Exception e) { ret = null; } return(ret); }
public void Update(Service service, ServiceFilter filter) { try { string cmd = string.Format("Update Service set " + "service_id = {0}, name = '{1}', description = '{2}', price = {3} ", service.service_id, service.name, service.description, service.price); List <string> wcmd = new List <string>(); if (!String.IsNullOrEmpty(filter.name)) { wcmd.Add("name LIKE '" + filter.name + "%'"); } if (!String.IsNullOrEmpty(filter.description)) { wcmd.Add("description LIKE '" + filter.description + "%'"); } if (filter.price.HasValue) { wcmd.Add("price = " + Helper.ToMyString(filter.price.ToString())); } if (filter.priceLowerThan.HasValue) { wcmd.Add("price < " + Helper.ToMyString(filter.priceLowerThan.ToString())); } if (filter.priceUpperThan.HasValue) { wcmd.Add("price > " + Helper.ToMyString(filter.priceUpperThan.ToString())); } if (wcmd.Count() > 0) { cmd += "where " + string.Join(" AND ", wcmd.ToArray()); } ExecuteNonQuery(cmd); } catch (Exception e) { Console.WriteLine("Error " + e.ToString()); Console.ReadKey(); } }
public ServiceFilter CreateFilter() { Console.Clear(); Console.WriteLine("Repository: SERVICE\n\n"); Console.WriteLine("Creating conditions for rows\n" + "You can skip some conditions\n" + "(select ... , where): "); ServiceFilter filter = new ServiceFilter(); Console.WriteLine("NAME: "); filter.name = Console.ReadLine(); Console.WriteLine("DESCRIPTION: "); filter.description = Console.ReadLine(); Console.WriteLine("PRICE: "); string a = Console.ReadLine(); if (a != "") { filter.price = Convert.ToDouble(a); } Console.WriteLine("PRICE lower than: "); string b = Console.ReadLine(); if (b != "") { filter.priceLowerThan = Convert.ToDouble(b); } Console.WriteLine("PRICE upper than: "); string c = Console.ReadLine(); if (c != "") { filter.priceUpperThan = Convert.ToDouble(c); } return(filter); }
private async void GetCourses() { var filter = new ServiceFilter(); if (!string.IsNullOrEmpty(Instructor)) { filter.Instructor = Instructor; } if (SelectedServiceType != null && SelectedServiceType.Id > 0) { filter.ServiceTypeId = _selectedServiceType.Id; } if (SelectedSportType != null && SelectedSportType.Id > 0) { filter.SportId = _selectedSportType.Id; } Courses = await _servicesProxy.GetCourses(filter); OnPropertyChanged("Courses"); }
private async void GetServices() { var filter = new ServiceFilter(); if (!string.IsNullOrEmpty(Customer)) { filter.Customer = _customer; } if (SelectedServiceType != null && SelectedServiceType.Id > 0) { filter.ServiceTypeId = _selectedServiceType.Id; } if (SelectedSportType != null && SelectedSportType.Id > 0) { filter.SportId = _selectedSportType.Id; } Services = await _servicesProxy.GetSingleServices(filter); OnPropertyChanged("Services"); }
public void Delete(ServiceFilter filter) { try { string cmd = "Delete from Service "; List <string> wcmd = new List <string>(); if (!String.IsNullOrEmpty(filter.name)) { wcmd.Add("name LIKE '" + filter.name + "%'"); } if (!String.IsNullOrEmpty(filter.description)) { wcmd.Add("description LIKE '" + filter.description + "%'"); } if (filter.price.HasValue) { wcmd.Add("price = " + Helper.ToMyString(filter.price.ToString())); } if (filter.priceLowerThan.HasValue) { wcmd.Add("price < " + Helper.ToMyString(filter.priceLowerThan.ToString())); } if (filter.priceUpperThan.HasValue) { wcmd.Add("price > " + Helper.ToMyString(filter.priceUpperThan.ToString())); } if (wcmd.Count() > 0) { cmd += "where " + string.Join(" and ", wcmd.ToArray()); } ExecuteNonQuery(cmd); } catch (Exception e) { Console.WriteLine("Error " + e.ToString()); Console.ReadKey(); } }