Ejemplo n.º 1
0
        /// <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> > GetCoursesWithoutCustomer(string customerEmail)
        {
            var ret = new ObservableCollection <DtoService>();

            try
            {
                using (var data = Context)
                {
                    var services = await data.Service
                                   .Where
                                       (s =>
                                       s.ServiceType.isCourse &&
                                       s.Customer.All(c => c.email != customerEmail)
                                       )
                                   .Take(TakeTop).ToListAsync();

                    foreach (var course in services)
                    {
                        ret.Add(ServiceConverter.DataAccessToDto(course));
                    }
                }
            }
            catch (Exception e)
            {
                ret = null;
            }
            return(ret);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///     Method returning course with specific id
        /// </summary>
        /// <param name="courseId">Id of course</param>
        /// <returns>Dto object of course</returns>
        public async Task <DtoService> GetCourse(int courseId)
        {
            DtoService course = null;

            using (var data = Context)
            {
                var service = await data.Service.FirstOrDefaultAsync(c => c.id == courseId);

                if (service != null)
                {
                    course = ServiceConverter.DataAccessToDto(service);
                }
            }
            return(course);
        }