private string GetPlaceName(object id) { try { using (Yetkilim.Web.Models.Ef.yetkilimDBContext db = new Yetkilim.Web.Models.Ef.yetkilimDBContext()) { db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; db.ChangeTracker.AutoDetectChangesEnabled = false; var id1 = (int)id; var name = db.Places.AsNoTracking().First(x => x.Id == id1).Name; return(name); } } catch (Exception ex) { return(""); } }
public async Task <IActionResult> Index() { try { DashboardViewModel model = new DashboardViewModel(); var table = string.Empty; var feedbackCount = 0; //var feedbackCount = 0; var isletmeAdi = string.Empty; using (Yetkilim.Web.Models.Ef.yetkilimDBContext db = new Yetkilim.Web.Models.Ef.yetkilimDBContext()) { db.ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking; db.ChangeTracker.AutoDetectChangesEnabled = false; var placesIds = new List <int?>(); if (base.CurrentUser.Role == UserRole.Admin) { var currentUserCompanyId = base.CurrentUser.CompanyId; placesIds = db.Places.Where(x => x.CompanyId == currentUserCompanyId).Select(x => (int?)x.Id).ToList(); } else if (base.CurrentUser.Role == UserRole.Dealer) { var currentPlaceId = base.CurrentUser.PlaceId; placesIds = db.Places.Where(x => x.Id == currentPlaceId).Select(x => (int?)x.Id).ToList(); var place = db.Places.FirstOrDefault(x => x.Id == currentPlaceId); if (place != null) { isletmeAdi += place.Name + " "; } } { table += "<br/>"; var temp = db.Feedback0.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "0"); } { table += "<br/>"; var temp = db.Feedback1.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray();; feedbackCount += temp.Length; table += myTableMaker(temp, "1"); } { table += "<br/>"; var temp = db.Feedback2.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "2"); } { table += "<br/>"; var temp = db.Feedback3.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "3"); } { table += "<br/>"; var temp = db.Feedback4.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "4"); } { table += "<br/>"; var temp = db.Feedback5.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "5"); } { table += "<br/>"; var temp = db.Feedback6.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "6"); } { table += "<br/>"; var temp = db.Feedback7.AsNoTracking() .WhereIf(base.CurrentUser.Role != UserRole.SuperAdmin, x => placesIds.Contains(x.PlaceId)).ToArray().OrderByDescending(x => x.CreatedDate ?? DateTime.Now).ToArray(); feedbackCount += temp.Length; table += myTableMaker(temp, "7"); } model.PlaceCount = base.CurrentUser.Role != UserRole.SuperAdmin ? placesIds.Count : db.Places.Count(); model.FeedbackCount = feedbackCount; } ViewBag.Table = table; ((dynamic)ViewBag).CompanyName = isletmeAdi + base.CurrentUser.CompanyName; return(View((object)model)); } catch (Exception ex) { LoggerExtensions.LogError(_logger, ex, "Panel Index Error", Array.Empty <object>()); return(this.RedirectToAction("SignOut")); } }