/// <summary> /// Gets a datacontext based on single transaction ID /// </summary> /// <returns>Returns a single transaction access datacontext</returns> public DataContextByTransaction(IIdentity userIdentity, Guid transactionId) : base(userIdentity) { //Vendor dependant entities. var authorizedVendorIds = ResolveAuthorizedVendors(); Vendors = new FilteredDbSet<Vendor>(this, v => authorizedVendorIds.Contains(v.ObjectId)); Features = new FilteredDbSet<Feature>(this, f => authorizedVendorIds.Contains(f.VendorId)); //License dependant entities. var authorizedLicenseIds = ResolveAuthorizedLicenses() .Concat(ResolveAuthorizedLicensesByTransactionId(transactionId)).ToList(); Licenses = new FilteredDbSet<License>(this, l => authorizedLicenseIds.Contains(l.ObjectId)); LicenseCustomerApps = new FilteredDbSet<LicenseCustomerApp>(this, lc => authorizedLicenseIds.Contains(lc.LicenseId)); //SKU dependant entities. var authorizedSkuIds = ResolveAuthorizedSKUsByAuthorizedLicenses() .Concat(ResolveAuthorizedSKUsByAuthorizedVendors()).ToList(); SKUs = new FilteredDbSet<SKU>(this, s => authorizedSkuIds.Contains(s.SkuId)); //Transaction items depends on current user role if (ContextIsForVendorAdmin()) { TransactionItems = new FilteredDbSet<TransactionItem>(this, ti => authorizedSkuIds.Contains(ti.SkuId)); } else { //Depends on licenses and provided transaction var transactionItemIdsByTransaction = ResolveAuthorizedTransactionItemsByTransactionId(transactionId); TransactionItems = new FilteredDbSet<TransactionItem>(this, ti => ((authorizedLicenseIds.Contains((Guid)ti.LicenseId)) || (transactionItemIdsByTransaction.Contains(ti.TransactionItemId)))); } var transactionIgnoredItemIdsByTransaction = ResolveAuthorizedTransactionIgnoredItemsByTransactionId(transactionId); TransactionIgnoredItems = new FilteredDbSet<TransactionIgnoredItem>(this, ti => transactionIgnoredItemIdsByTransaction.Contains(ti.TransactionItemId)); //Transaction Items app dependant entities var authorizedTransactions = ResolveAuthorizedTransactionsByAuthorizedTransactionItems(); Transactions = new FilteredDbSet<Transaction>(this, t => authorizedTransactions.Contains(t.TransactionId)); //Customer app dependant entities var authorizedCustomerApps = (from c in LicenseCustomerApps select c.CustomerAppId).ToList(); CustomerApps = new FilteredDbSet<CustomerApp>(this, c => authorizedCustomerApps.Contains(c.CustomerAppId)); CustomerAppIssues = new FilteredDbSet<CustomerAppIssue>(this, c => authorizedCustomerApps.Contains(c.CustomerAppId)); //Customer dependant entities var authorizedCustomerIds = ResolveAuthorizedCustomersByAuthorizedLicenses() .Concat(ResolveAuthorizedCustomers()).ToList(); Customers = new FilteredDbSet<Customer>(this, c => authorizedCustomerIds.Contains(c.ObjectId)); }
public override void SetUp() { base.SetUp(); firstTenant = Presto.Persist <Tenant>(); firstUser = Presto.Create <User>(); firstTenant.Users.Add(firstUser); secondTenant = Presto.Persist <Tenant>(); secondUser = Presto.Create <User>(); secondTenant.Users.Add(secondUser); ClarityDB.Instance.SaveChanges(); filter = x => x.TenantID == firstTenant.ID; users = new FilteredDbSet <User>((ClarityDB)ClarityDB.Instance, filter); }
public MainBcUnitOfWork(ISessionHandler sessionHandler) { _sessionHandler = sessionHandler; var tenantId = sessionHandler.GetTenantId(); if (tenantId > 0) { Tenant = new FilteredDbSet <Tenant>(this); Pessoa = new FilteredDbSet <Pessoa>(this, c => c.TenantId == tenantId, c => c.TenantId = tenantId); Usuario = new FilteredDbSet <Usuario>(this, c => c.TenantId == tenantId, c => c.TenantId = tenantId); } else { Tenant = CreateSet <Tenant>(); Pessoa = CreateSet <Pessoa>(); Usuario = CreateSet <Usuario>(); } }
// public JournalEntryContext db = new JournalEntryContext(User); public ActionResult Index(string currentFilter, string searchString, string sortBy, string isAsc, int?page, int?itemsPerPage, string HostingEntity, int?HostingEntityID, string AssociatedType, bool?IsExport, bool?IsDeepSearch, bool?IsMobileRequest, bool?IsFilter, bool?RenderPartial, string FilterHostingEntityID, string FilterHostingEntity, bool?isHomePage, string ExtraIds) { JournalEntryContext db = new JournalEntryContext(User); if (string.IsNullOrEmpty(isAsc) && !string.IsNullOrEmpty(sortBy)) { isAsc = "ASC"; } ViewBag.isAsc = isAsc; ViewBag.CurrentSort = sortBy; ViewData["HostingEntity"] = HostingEntity; ViewData["HostingEntityID"] = HostingEntityID; ViewData["AssociatedType"] = AssociatedType; ViewData["FilterHostingEntity"] = FilterHostingEntity; ViewData["FilterHostingEntityID"] = FilterHostingEntityID; EntityNameJournal = AssociatedType; ViewData["IsFilter"] = IsFilter.HasValue ? IsFilter.Value : false; if (searchString != null) { page = null; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var lstJournal = from s in db.JournalEntries select s; if (HostingEntity != null && HostingEntityID != null) { if (isHomePage != null && isHomePage.Value) { lstJournal = lstJournal.Where(p => p.EntityName == HostingEntity && (p.Type == "Modified" || p.Type == "Added" || p.Type == "Deleted") && p.PropertyName != "T_RecordAddedInsertBy" && p.PropertyName != "T_RecordAddedInsertBy" && p.PropertyName != "T_RecordAddedInsertDate" && p.PropertyName != "T_RecordAdded"); lstJournal = lstJournal.GroupBy(p => p.RecordId, (key, g) => g.OrderByDescending(e => e.DateTimeOfEntry).FirstOrDefault()); lstJournal = sortRecords(lstJournal.Where(p => p.Type != "Deleted"), "DateTimeOfEntry", "desc"); lstJournal = lstJournal.Take(5); ViewBag.IsHomePage = isHomePage.Value; } else { lstJournal = new FilteredDbSet <JournalEntry>(db, d => d.Id > 0); lstJournal = lstJournal.Where(p => p.EntityName == HostingEntity && p.RecordId == HostingEntityID).OrderByDescending(p => p.Id); try { Type controller = Type.GetType("GeneratorBase.MVC.Controllers." + HostingEntity + "Controller"); object objController = Activator.CreateInstance(controller, null); System.Reflection.MethodInfo mc = controller.GetMethod("GetExtraJournalEntry"); object[] MethodParams = new object[] { HostingEntityID, User, db }; var obj = mc.Invoke(objController, MethodParams); var listJournal = (IQueryable <JournalEntry>)obj; lstJournal = listJournal.Union(lstJournal).Distinct().OrderByDescending(p => p.Id); } catch {} } } if (FilterHostingEntity != null && FilterHostingEntityID != null) { var hostid = Convert.ToInt64(FilterHostingEntityID); lstJournal = lstJournal.Where(p => p.EntityName == FilterHostingEntity && p.RecordId == hostid).OrderByDescending(p => p.Id); ViewData["HostingEntity"] = FilterHostingEntity; ViewData["HostingEntityID"] = FilterHostingEntityID; } // if (!string.IsNullOrEmpty(ExtraIds)) { List <long> ids = ExtraIds.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(Int64.Parse).ToList(); lstJournal = db.JournalEntries.Where(p => ids.Contains(p.Id)).Union(lstJournal).Distinct().OrderByDescending(p => p.Id); } // if (!String.IsNullOrEmpty(searchString)) { lstJournal = searchRecords(lstJournal, searchString.ToUpper(), IsDeepSearch); } if ((IsFilter == null ? false : IsFilter.Value) && HostingEntity == "EntityName") { lstJournal = lstJournal.Where(p => p.EntityName == AssociatedType).OrderByDescending(p => p.Id); } if ((IsFilter == null ? false : IsFilter.Value) && HostingEntity == "Type") { lstJournal = lstJournal.Where(p => p.Type == AssociatedType).OrderByDescending(p => p.Id); } if ((IsFilter == null ? false : IsFilter.Value) && HostingEntity == "UserName") { lstJournal = lstJournal.Where(p => p.UserName == AssociatedType).OrderByDescending(p => p.Id); } if ((IsFilter == null ? false : IsFilter.Value) && HostingEntity == "PropertyName") { lstJournal = lstJournal.Where(p => p.PropertyName == AssociatedType).OrderByDescending(p => p.Id); } if (!String.IsNullOrEmpty(sortBy) && !String.IsNullOrEmpty(isAsc) && isHomePage == null) { lstJournal = sortRecords(lstJournal, sortBy, isAsc); } else { lstJournal = lstJournal.OrderByDescending(c => c.Id); } int pageSize = 10; int pageNumber = (page ?? 1); ViewBag.Pages = page; if (itemsPerPage != null) { pageSize = (int)itemsPerPage; ViewBag.CurrentItemsPerPage = itemsPerPage; } var _JournalEntry = lstJournal; if (Convert.ToBoolean(IsExport)) { pageNumber = 1; if (_JournalEntry.Count() > 0) { pageSize = _JournalEntry.Count(); } return(View("ExcelExport", _JournalEntry.ToPagedList(pageNumber, pageSize))); } if (IsMobileRequest != true) { if (Request.AcceptTypes.Contains("text/html")) { if (!(RenderPartial == null ? false : RenderPartial.Value) && !Request.IsAjaxRequest()) { return(View(_JournalEntry.ToPagedList(pageNumber, pageSize))); } else { return(PartialView("IndexPartial", _JournalEntry.ToPagedList(pageNumber, pageSize))); } } else if (Request.AcceptTypes.Contains("application/json")) { var Result = getJournalEntryList(_JournalEntry); return(Json(Result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } } else { var Result = getJournalEntryList(_JournalEntry); return(Json(Result, "application/json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet)); } if (!(RenderPartial == null ? false : RenderPartial.Value) && !Request.IsAjaxRequest()) { return(View(_JournalEntry.ToPagedList(pageNumber, pageSize))); } else { return(PartialView("IndexPartial", _JournalEntry.ToPagedList(pageNumber, pageSize))); } }