public IEnumerable <TaskDTO> GetToDoEntities() { var entities = taskRepo.GetWithInclude(o => o.TaskStatusId == (int)StatusEnum.ToDo, p => p.TaskCategory, k => k.Comments); var dtos = mapper.Map <IEnumerable <Task>, IEnumerable <TaskDTO> >(entities); return(dtos); }
private IEnumerable <Log> SearchEvents(IDataTablesRequest requestModel, EventsSearchBox searchViewModel, out int filteredCount) { EFGenericRepository <Log> Lg = new EFGenericRepository <Log>(DbContext); DateTime dtF = searchViewModel.FromDate == null ? DateTime.Now.Date : DateTime.Parse(searchViewModel.FromDate); DateTime dtT = searchViewModel.ToDate == null?DateTime.Now.Date.AddHours(24).AddMilliseconds(-1) : DateTime.ParseExact(searchViewModel.ToDate, "dd/MM/yyyy HH:mm:ss", null); IEnumerable <Log> query = Lg.GetWithInclude(x => x.Dt >= dtF && x.Dt <= dtT); #region Filtering if (requestModel.Search.Value != string.Empty) { var value = requestModel.Search.Value.Trim(); query = query.Where(p => p.Typ.Contains(value)); } #endregion Filtering filteredCount = query.Count(); #region Sorting // Sorting var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; foreach (var column in sortedColumns) { orderByString += orderByString != String.Empty ? "," : ""; orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc"); } query = query.OrderBy(orderByString == string.Empty ? "Dt asc" : orderByString); #endregion Sorting return(query); }
private void FillOrgs() { string Owner = User.Identity.GetUserId(); if (Owner == null) { return; } EFGenericRepository <OrgUsersViewModel> OrgUsers = new EFGenericRepository <OrgUsersViewModel>(DbContext); IEnumerable <OrgUsersViewModel> query = null; query = OrgUsers.GetWithInclude(x => x.User_Id == Owner); ViewBag.MyOrgList = query; }
private IEnumerable <Org> SearchOrgs(IDataTablesRequest requestModel, Org model, out int filteredCount) { EFGenericRepository <Org> Orgs = new EFGenericRepository <Org>(DbContext); IEnumerable <Org> query = null; string Owner = User.Identity.GetUserId(); if (model.Name == null) { query = Orgs.GetWithInclude(x => x.Owner == Owner); } else { query = Orgs.GetWithInclude(x => x.Name.Contains(model.Name) && x.Owner == Owner); } #region Filtering if (requestModel.Search.Value != string.Empty) { var value = requestModel.Search.Value.Trim(); query = query.Where(p => p.Name.Contains(value)); } #endregion Filtering filteredCount = query.Count(); #region Sorting // Sorting var sortedColumns = requestModel.Columns.GetSortedColumns(); var orderByString = String.Empty; foreach (var column in sortedColumns) { orderByString += orderByString != String.Empty ? "," : ""; orderByString += (column.Data) + (column.SortDirection == Column.OrderDirection.Ascendant ? " asc" : " desc"); } query = query.OrderBy(orderByString == string.Empty ? "Name asc" : orderByString); #endregion Sorting return(query); }
public void SortMethod() { // Получаем список основных каталогов IEnumerable <catalog> catalog = ICatalog.Get(); // Используем их для начала работы foreach (var Catalog in catalog) { // Добавляем основные каталоги ICatalog_level.Create(new catalog_level() { name = Catalog.name, description = Catalog.description }); // Загружаем дочерний элемент foreach (var Catalog_aggregate in ICatalog_aggregate.GetWithInclude(a => a.catalog_model).Where(a => a.catalog_id == Catalog.Id)) { // Получаем id первого созданного родительского элемента int MainId = ICatalog_level.Get().Where(a => a.parent_id == null).LastOrDefault().id; // Добавляем дочерний элемент первого уровня ICatalog_level.Create(new catalog_level() { name = Catalog_aggregate.name, description = Catalog_aggregate.description, parent_id = MainId // Присваиваем ему идентификатор родителя }); // Находим новый Id дочернего элемента первого уровня int?newId = ICatalog_level.Get().Where(x => x.parent_id == MainId).LastOrDefault().id; // Используем дочерний элемент второго уровня foreach (var Catalog_model in Catalog_aggregate.catalog_model) { // Добавляем дочерний элемент второго уровня ICatalog_level.Create(new catalog_level() { name = Catalog_model.model, description = Catalog_model.description, parent_id = newId // Присваиваем дочернему элементу второго уровня, Id идентификатор дочернего элемента первого уровня }); } } } }
// GET: Org/Edit public ActionResult Edit(string id) { EFGenericRepository <Org> Orgs = new EFGenericRepository <Org>(DbContext); Org model = new Org(); IEnumerable <Org> query = Orgs.GetWithInclude(x => x.Id == id); foreach (var item in query) { model = item; break; } if (Request.IsAjaxRequest()) { return(PartialView("_EditPartial", model)); } return(View(model)); }
static void Main(string[] args) { EFGenericRepository <Manager> managerRepo = new EFGenericRepository <Manager> (new DAL.Contexts.AppContext()); EFGenericRepository <SaleInfo> salesRepo = new EFGenericRepository <SaleInfo> (new DAL.Contexts.AppContext()); IEnumerable <Manager> managers = managerRepo.GetWithInclude(p => p.Info); foreach (Manager m in managers) { Console.WriteLine($"Manager: {m.ManagerName}"); foreach (SaleInfo p in m.Info) { Console.WriteLine($"{p.Date}, {p.ClientName}, {p.Cost}"); } Console.WriteLine(); } managerRepo.Dispose(); }
static void Main(string[] args) { Console.WriteLine("Start Program ...\n"); Console.WriteLine("-----> University <--------"); using (StudentContext sc = new StudentContext()) { var universities = sc.Universities.ToList(); foreach (var university in universities) { Console.WriteLine($"{university.Id}, {university.Name}, {university.Description}"); } } Console.WriteLine("\n-----> Course <--------"); using (StudentContext sc = new StudentContext()) { var courses = sc.Courses.ToList(); foreach (var course in courses) { Console.WriteLine($"{course.Id}, {course.Name}, {course.Description}, {course.Faculty?.Name}"); } } EFGenericRepository <StudentFirstCore.Models.Universities> universityRepo = new EFGenericRepository <StudentFirstCore.Models.Universities>(new StudentContext()); IEnumerable <StudentFirstCore.Models.Universities> universities29 = universityRepo.GetWithInclude(u => u.Faculties); foreach (StudentFirstCore.Models.Universities university in universities29) { Console.WriteLine($"{university.Name} ({university.Description}) Faculties:"); foreach (var f in university.Faculties) { Console.WriteLine($"\t{f.Name}, {f.Description}, {f.Address}"); } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// Console.WriteLine("-----------------------------------------------"); using (var context = new StudentContext()) { //Grouping Console.WriteLine("\n---> Group --->"); var universities = context.Universities.GroupBy(x => x.Name) .Select(x => new { Name = x.Key, AvgAge = x.Average(y => y.Age) }); var universities2 = context.Faculties.Where(x => x.Name != null) .GroupBy(x => x.Name) .Select(x => new { Name = x.Key, Count = x.Count(m => m.Universtity != null) }) .Where(x => x.Count >= 1); //GROUPJOIN Console.WriteLine("\n---> Group join --->"); var topUniversities = context.Universities.GroupBy(x => x.Name) .Select(x => new { Name = x.Key, CountFaculties = x.Average(y => y.Faculties.Count) }) .OrderByDescending(x => x.Name); var Universities2 = topUniversities.GroupJoin( context.Universities, x => x.Name, x => x.Name, (u, Descriptions) => new { u.Name, Descriptions = Descriptions.Select(y => y.Description).ToList() }); Console.WriteLine("\n---> Subqueries: Select example <---"); var teachers = context .Teachers .Select(x => new { Name = x.FirstName + x.LastName, Marks = x.Marks.Average(y => y.Value) }); Console.WriteLine("---> Subqueries: Filter example (ALL & ANY) <---"); Console.WriteLine("\nAll"); var topTeachersAll = context.Teachers .Where(x => x.Marks.All(y => y.Value >= 8)); Console.WriteLine("\nAny"); var topTeachersAny = context.Teachers .Where(x => x.Marks.Any(y => y.Value >= 8)); Console.WriteLine("\nCASE WHEN"); var ageRangeUniversity = context.Universities .Select(x => new { Description = x.Description ?? "mising description", AgeRange = x.Age >= 0 && x.Age < 10 ? "0-10" : x.Age > 10 ? "old university" : "default" }); //cursuri une nui nis un student(profesor) cu note mai mic de 4 context.Courses.Where(x => x.Marks.All(c => c.Value > 4)); //teacher care nu au note mai mari ca 4 context.Teachers.Where(x => x.Marks.All(s => s.Value > 4)); //teacher cite comentarii are, ++++ si media la note context.Teachers.Select(x => new { Teacher = x.FirstName, Comments = x.Comments.Count(), AvgNote = x.Marks.Average(d => d.Value) }); var otherr = context.Universities.FromSql("SELECT * FROM Universities WHERE Age > 0") .Select(x => new { x.Name }); Console.WriteLine("---> dynamic <---"); IQueryable <Universities> queryUniversity = context.Universities; IQueryable <Universities> universityDynamic = FilterDeviceList(queryUniversity, new Universities { Name = "UTM" }); foreach (Universities university in universityDynamic) { Console.WriteLine($"{university.Name}, {university.Description}, {university.Age}"); } } Console.WriteLine("\n---> End Program <---"); Console.ReadKey(); }