Exemplo n.º 1
0
        public async Task <IActionResult> First()
        {
            string path           = Request.Path.Value.ToLower();
            Book   BookFromMemory = (Book)_memoryCache.Get(path);

            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Book, Jenre> elems = null;
            HttpContext.Session.Get("First");
            if (HttpContext.Session.Get("first") != null)
            {
                string   str  = HttpContext.Session.GetString("first");
                string[] strM = str.Split(";");
                Book     book = new Book();

                book.RegistrationNumber = Convert.ToInt32(strM[0]);
                book.Name          = strM[1];
                book.Author        = strM[2];
                book.Edition       = strM[3];
                book.JenreID       = Convert.ToInt32(strM[4]);
                book.YearOfEdition = Convert.ToInt32(strM[5]);
                book.Price         = (float)Convert.ToDouble(strM[6]);
                ViewData["first"]  = book;
            }
            else
            {
                using (LibraryContext db = new LibraryContext())
                {
                    ViewData["Jenres"] = db.Jenres.ToList();
                    string str = JsonConvert.SerializeObject(db.Jenres.ToList());

                    HttpContext.Session.SetString("First", str);
                }
            }
            using (LibraryContext db = new LibraryContext())
            {
                elems = db.Books.Include(x => x.Jenre);
                ViewData["Jenres"]         = db.Jenres.ToList();
                ViewData["BookFromMemory"] = BookFromMemory;
                return(View(await elems.ToListAsync()));
            }
        }
Exemplo n.º 2
0
        public async Task <IQueryable <Product> > GetAll(
            string keyword,
            decimal?minPrice,
            decimal?maxPrice,
            DateTime?minCreateDate,
            DateTime?maxCreateDate,
            long?brandId,
            long[] categories
            )
        {
            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Product, Domain.Brand.Brand> result = ProductRepository
                                                                                                            .GetAll()
                                                                                                            .Include(s => s.ProductImages)
                                                                                                            .ThenInclude(s => s.Image)
                                                                                                            .Include(s => s.CoverImage)
                                                                                                            .ThenInclude(s => s.Image)
                                                                                                            .Include(s => s.Brand);

            return(result);
        }
Exemplo n.º 3
0
 public IncludableQueryable(Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <TEntity, TProperty> includableQueryable)
 {
     this.includableQueryable = includableQueryable;
 }
Exemplo n.º 4
0
 // GET: Reports
 public async Task <IActionResult> Index()
 {
     Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Report, Wagon> applicationDbContext = _context.Reports.Include(r => r.DevicePlace).Include(r => r.DeviceStatus).Include(r => r.ParentReport).Include(r => r.Reporter).Include(r => r.Wagon);
     return(View(await applicationDbContext.ToListAsync()));
 }
Exemplo n.º 5
0
        public async Task <IActionResult> GetUserContacts(string phone)
        {
            try
            {
                Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <User, ICollection <Contact> > included = _unitOfWork.UserRepository.GetDbSet().Include(u => u.Contacts);
                User user = await included.SingleOrDefaultAsync(u => u.Phone == phone);

                List <Contact> contacts = user.Contacts.ToList();
                var            x        = from contact in contacts
                                          select new
                {
                    Id     = contact.Id,
                    Name   = contact.Name,
                    UserId = contact.User.Id
                };
                return(Ok(x));
            }
            catch (Exception e)
            {
                _logger.LogError(e, e.Message);
                return(Problem(e.Message));
            }
        }
Exemplo n.º 6
0
 public EfIncludableQuerable(Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <TEntity, TProperty> query)
 {
     _query = query;
 }
Exemplo n.º 7
0
        public async Task DeleteAllAsync()
        {
            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <PropertyListing, List <PropertyFloorplan> > all = _db.Properties
                                                                                                                        .Include(p => p.Metadata)
                                                                                                                        .Include(p => p.Media)
                                                                                                                        .Include(p => p.FloorPlans);

            all.ForEach(p =>
            {
                p.Media.ForEach(async m =>
                {
                    try { await _media.DeleteStoredMedia(m); } catch (Exception) { }
                    _db.Entry(m).State = EntityState.Deleted;
                });
                p.FloorPlans.ForEach(async m =>
                {
                    try { await _media.DeleteStoredMedia(m); } catch (Exception) { }
                    _db.Entry(m).State = EntityState.Deleted;
                });
                p.Metadata.ForEach(m =>
                {
                    _db.Entry(m).State = EntityState.Deleted;
                });
            });
            await _db.SaveChangesAsync();

            all.ForEach(p =>
            {
                _db.Entry(p).State = EntityState.Deleted;
            });
            await _db.SaveChangesAsync();

            ClearPropertyCache();
        }
        public async Task <IActionResult> Index(int?id)
        {
            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Funcion, TipoSala> miContexto = default;

            if (id == null)
            {
                if (User.IsInRole("Empleado"))
                {
                    miContexto = _context.Funciones
                                 .Include(f => f.Pelicula)
                                 .Include(f => f.Sala)
                                 .Include(f => f.Pelicula.Genero)
                                 .Include(f => f.Reservas)
                                 .Include(f => f.Sala.TipoSala);
                }
                else
                {
                    miContexto = _context.Funciones.Where(f => f.Fecha >= DateTime.Today && f.Fecha <= DateTime.Today.AddDays(7))
                                 .Include(f => f.Pelicula)
                                 .Include(f => f.Sala)
                                 .Include(f => f.Pelicula.Genero)
                                 .Include(f => f.Reservas)
                                 .Include(f => f.Sala.TipoSala);
                }
            }
            else
            {
                if (User.IsInRole("Empleado"))
                {
                    miContexto = _context.Funciones.Where(f => f.PeliculaId == id)
                                 .Include(f => f.Pelicula)
                                 .Include(f => f.Sala)
                                 .Include(f => f.Pelicula.Genero)
                                 .Include(f => f.Reservas)
                                 .Include(f => f.Sala.TipoSala);
                }
                else
                {
                    miContexto = _context.Funciones.Where(f => f.PeliculaId == id && f.Fecha >= DateTime.Today && f.Fecha <= DateTime.Today.AddDays(7))
                                 .Include(f => f.Pelicula)
                                 .Include(f => f.Sala)
                                 .Include(f => f.Pelicula.Genero)
                                 .Include(f => f.Reservas)
                                 .Include(f => f.Sala.TipoSala);
                }
            }

            //Intente hacer un Concat para no tener tantos if anidados pero no me salio
            //La idea era tener la reestriccion de fecha, y si el rol es empleado
            //concatenarle las funciones en el pasado.

            //if (User.IsInRole("Empleado"))
            //{
            //    miContexto.Concat(_context.Funciones.Where(f => f.Fecha < DateTime.Today)
            //                               .Include(f => f.Pelicula)
            //                              .Include(f => f.Sala)
            //                              .Include(f => f.Pelicula.Genero)
            //                              .Include(f => f.Reservas)
            //                              .Include(f => f.Sala.TipoSala));
            //}

            return(View(await miContexto.ToListAsync()));
        }
Exemplo n.º 9
0
        public async Task Sync()
        {
            List <Vm> vms = new List <Vm>();

            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Adapter, Credentials> adapters = _context.Adapters.Where(x => x.IsOK).Include(x => x.Provider).Include(a => a.Credentials);
            foreach (Adapter adapter in adapters)
            {
                if (!adapter.IsOK)
                {
                    break;
                }
                switch (adapter.Provider.Name.ToLower())
                {
                case "ovirt":
                    ServicesResponse servicesResponse = await VmService.GetFullVms(adapter);

                    if (!servicesResponse.isSuccess)
                    {
                        break;
                    }
                    List <Vm> commonVMs = (List <Vm>)servicesResponse.resultObject;

                    vms.AddRange(commonVMs);
                    break;
                }
            }
            var oldVms = await _context.Vms.ToListAsync();

            _context.Vms.RemoveRange(oldVms);

            vms.ConvertAll(x => x.LastTimeUpdated = DateTime.Now);
            _context.Vms.AddRange(vms);
            //foreach (var vm in vms)
            //{
            //    var entity = _context.Vms.Find(vm.Id);
            //    if (entity == null)
            //    {
            //        _context.Vms.Add(vm);
            //    }
            //    else
            //    {
            //        _context.Entry(entity).CurrentValues.SetValues(vm);
            //    }
            //}

            await _context.SaveChangesAsync();
        }
Exemplo n.º 10
0
 public async Task <IActionResult> Index()
 {
     Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Project, Customer> vPMDBContext = _context.Projects.Include(p => p.Customer);
     return(View(await vPMDBContext.ToListAsync()));
 }
Exemplo n.º 11
0
 // GET: Aulas
 public async Task <IActionResult> Index()
 {
     Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Aula, Admin> healthUpContext = _context.Aulas.Include(a => a.NumAdminNavigation).ThenInclude(a => a.NumAdminNavigation).Include(a => a.NumProfessorNavigation).ThenInclude(a => a.NumAdminNavigation);
     return(View(await healthUpContext.ToListAsync()));
 }
Exemplo n.º 12
0
 // GET: Payments
 public async Task <IActionResult> Index()
 {
     Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Payment, Category> paymentsContext = _context.Payments.Include(p => p.Category);
     return(View(await paymentsContext.ToListAsync()));
 }
Exemplo n.º 13
0
        public JsonResult IndexJson(DataTableClass responseBody)
        {
            DataTableClass test1 = responseBody;

            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Payment, Category> paymentsContext = _context.Payments.Include(p => p.Category);

            // return Json("{\"draw\": 1,\"recordsTotal\": 3,\"recordsFiltered\": 3,\"data\":"+ Json(paymentsContext.Take(3)) +"}");

            string test2 = "{\"draw\": 1,\"recordsTotal\": 3,\"recordsFiltered\": 3,\"data\":[{\"id\":1,\"payDate\":\"2018-07-31T00:00:00\",\"amount\":1,\"description\":\"111\",\"catogoryId\":1,\"category\":{\"id\":1,\"name\":\"CDA\",\"isActive\":true}},{\"id\":2,\"payDate\":\"2018-08-07T15:00:00\",\"amount\":2345789,\"description\":\"dfh dj\",\"catogoryId\":6,\"category\":{\"id\":6,\"name\":\"ENJ\",\"isActive\":true}},{\"id\":1003,\"payDate\":\"2018-08-09T11:03:00\",\"amount\":3457,\"description\":\"eyjtjrj\",\"catogoryId\":9,\"category\":{\"id\":9,\"name\":\"HLS\",\"isActive\":true}}]}";

            string test = "{\"draw\":1,\"recordsTotal\":11,\"recordsFiltered\":11,\"data\":[[\"Airixi\",\"Satou\",\"Accountant\",\"Tokyo\",\"28th Nov 08\",\"$162,700\"],[\"Angeli\",\"Ramos\",\"Chief Executive Officer (CEO)\",\"London\",\"9th Oct 09\",\"$1,200,000\"],[\"Ashton\",\"Cox\",\"Junior Technical Author\",\"San Francisco\",\"12th Jan 09\",\"$86,000\"],[\"Bradly\",\"Greer\",\"Software Engineer\",\"London\",\"13th Oct 12\",\"$132,000\"],[\"Brendn\",\"Wagner\",\"Software Engineer\",\"San Francisco\",\"7th Jun 11\",\"$206,850\"],[\"Brielo\",\"Williamson\",\"Integration Specialist\",\"New York\",\"2nd Dec 12\",\"$372,000\"],[\"Brunos\",\"Nash\",\"Software Engineer\",\"London\",\"3rd May 11\",\"$163,500\"],[\"Caesar\",\"Vance\",\"Pre-Sales Support\",\"New York\",\"12th Dec 11\",\"$106,450\"],[\"Carata\",\"Stevens\",\"Sales Assistant\",\"New York\",\"6th Dec 11\",\"$145,600\"],[\"Cedric\",\"Kelly\",\"Senior Javascript Developer\",\"Edinburgh\",\"29th Mar 12\",\"$433,060\"]]}";

            return(Json(test));
            //return test2;
        }
Exemplo n.º 14
0
        public async Task <IActionResult> Index()
        {
            Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <User, System.Collections.Generic.ICollection <Publication> > users = _dataContext.Users.Include(u => u.Publications);

            //TODO: fix user roles, try select
            foreach (User user in users)
            {
                // TODO: change hardcode roleName
                user.IsManager = await _userHelper.IsInRoleAsync(user.Email, "Manager");
            }
            ;

            return(View(users));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Finds one element (with the given includes) based on the Id.
        /// </summary>
        /// <param name="id">The id of the element to find</param>
        /// <param name="listNavigationPropertyPath">The given includes</param>
        /// <returns>One element (with the given includes) based on the Id.</returns>
        public virtual T Find <T>(Guid id, params Expression <Func <T, ModelBase> >[] listNavigationPropertyPath) where T : ModelBase
        {
            Logger.Init(nameof(CRUDRepository), nameof(Find), User);
            Logger.Info("Start");

            try
            {
                Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <T, ModelBase> previousInclude = Context.Set <T>().Include(listNavigationPropertyPath[0]);

                if (listNavigationPropertyPath.Length > 1)
                {
                    for (int i = 1; i < listNavigationPropertyPath.Length; i++)
                    {
                        previousInclude = previousInclude.Include(listNavigationPropertyPath[i]);
                    }
                }

                Logger.Info("Success");
                return(previousInclude.Single(x => x.Id == id));
            }
            catch (Exception exception)
            {
                Logger.Error("Failure", exception);
                throw exception;
            }
        }
Exemplo n.º 16
0
 // GET: Orders
 public async Task <IActionResult> Index()
 {
     Microsoft.EntityFrameworkCore.Query.IIncludableQueryable <Order, Customer> certitrackContext = _context.Order
                                                                                                    .Include(o => o.OrderItems)
                                                                                                    .Include(o => o.Customer);
     return(View(await certitrackContext.ToListAsync()));
 }