public async Task GetActualProject(string town, int lastId = 0)//<List<ProjectShort>> { string userId = AuthJWT.GetCurrentId(HttpContext, out int status); if (status != 0 || userId == null) { userId = null; } //List<ProjectShort> res = new List<ProjectShort>(); int?townId = null; if (town != null) { string townLower = town.ToLower().Trim(); var townDb = await Town.GetByName(_db, townLower); if (townDb == null) { return;// new List<ProjectShort>(); } townId = townDb.Id; } var res = await Project.GetActualShortEntityWithStatus(_db, townId, userId, lastId); await ProjectShort.SetMainImages(_db, res); //return res; Response.ContentType = "application/json"; await Response.WriteAsync(JsonConvert.SerializeObject(res, new JsonSerializerSettings { Formatting = Formatting.Indented })); }
//все проекты не зависимо от статуса public async static Task <List <ProjectShort> > GetProjectsByActual(ApplicationDbContext db, int companyId, int?townId, int lastId) { var res = await Project.GetActualQueryEntityWithCompany(db, townId, companyId, lastId);//GetActualQueryEntity(db, townId).Where(x1 => x1.CompanyId == companyId).Select(x1 => new ProjectShort(x1.Name, x1.Id)).ToListAsync(); await ProjectShort.SetMainImages(db, res); return(res); }
//без осртировки, все записи public async static Task <List <ProjectShort> > GetShortsData(ApplicationDbContext db) { var res = await db.Projects.Select(x1 => new ProjectShort(x1.Name, x1.Id)).ToListAsync(); await ProjectShort.SetMainImages(db, res); return(res); }
//проекты в которые пользователь подал заявки, картинки устанавливаются,без сортировки по актуальности public async static Task <List <ProjectShort> > GetUserRequests(ApplicationDbContext db, string userId, StatusInProject statusInProject) { var res = await db.ProjectUsers.Where(x1 => x1.UserId == userId && x1.Status == statusInProject). Join(db.Projects, x1 => x1.ProjectId, x2 => x2.Id, (x1, x2) => x2).Select(x1 => new ProjectShort(x1.Name, x1.Id) { Status = statusInProject }).ToListAsync(); await ProjectShort.SetMainImages(db, res); return(res); }
//получаем сокращенные данные, не учитывая статус проекта public async static Task <List <ProjectShort> > GetActualShortEntityWithStatus(ApplicationDbContext db, int?townId, string userId, int lastId) { var projs = await Project.GetActualQueryEntityWithStatus(db, townId, lastId).Select(x1 => new ProjectShort(x1.Name, x1.Id)).ToListAsync(); await ProjectShort.SetMainImages(db, projs); if (string.IsNullOrWhiteSpace(userId)) { return(projs); } await Project.SetUserStatusInProject(db, projs, userId); //var status = await db.ProjectUsers.Where(x1 => x1.UserId == userId && projs.FirstOrDefault(x2 => x2.ProjectId == x1.ProjectId) != null).ToListAsync(); //status.ForEach(x1 => //{ // var tmp = projs.FirstOrDefault(x2 => x2.ProjectId == x1.ProjectId); // if (tmp != null) // tmp.Status = x1.Status; //}); return(projs); }