public async Task <IActionResult> GetAsync([FromRoute] Guid organizationuuid, [FromRoute] Guid uuid) { //note: //org users and org roles are read from mh meta db! //This is where some env core objects are kept //ensure user belongs to an org if (await OrganizationContext.IsOrgMemberAsync(GetDefaultDbContext(), uuid)) { var user = (await base.GetAsync(uuid, GetDefaultDbContext())).GetContent <MapHiveUser>(); if (user == null) { return(NotFound()); } //just check for owner / admin roles; it is an org member anyway if (await OrganizationContext.IsOrgOwnerAsync(GetDefaultDbContext(), user)) { user.OrganizationRole = Organization.OrganizationRole.Owner; } else if (await OrganizationContext.IsOrgAdminAsync(GetDefaultDbContext(), user)) { user.OrganizationRole = Organization.OrganizationRole.Admin; } else { user.OrganizationRole = Organization.OrganizationRole.Member; } return(Ok(user)); } return(NotFound()); }
public async Task <IActionResult> GetAsync([FromRoute] Guid organizationuuid, [FromQuery] string sort = null, [FromQuery] string filter = null, [FromQuery] int start = 0, [FromQuery] int limit = 25) { try { //note: //org users and org roles are read from mh meta db! //This is where some env core objects are kept var users = await OrganizationContext.GetOrganizationAssetsAsync <MapHiveUser>(GetDefaultDbContext(), sort, filter, start, limit); if (users == null) { return(NotFound()); } var roles2users = await OrganizationContext.GetOrgRoles2UsersMapAsync(GetDefaultDbContext()); foreach (var user in users?.assets) { user.OrganizationRole = OrganizationContext.GetUserOrgRole(roles2users, user.Uuid); } HttpContext.AppendTotalHeader(users?.count ?? 0); return(Ok(users?.assets)); } catch (Exception ex) { return(HandleException(ex)); } }
public ClaimViewModelController(ClaimContext claimContext, PatientContext patientContext, OrganizationContext organizationContext, IMapper mapper) { _claimContext = claimContext; _patientContext = patientContext; _organizationContext = organizationContext; _mapper = mapper; }
public void Setup() { var loan = new List <Product> { new Product { Id = 1, Name = "Dummy1", Price = 30, Category = "Toy" }, new Product { Id = 2, Name = "Dummy1", Price = 60, Category = "Toy" }, new Product { Id = 4, Name = "Dummy1", Price = 30, Category = "Toy" } }; var loandata = loan.AsQueryable(); var mockSet = new Mock <DbSet <Product> >(); mockSet.As <IQueryable <Product> >().Setup(m => m.Provider).Returns(loandata.Provider); mockSet.As <IQueryable <Product> >().Setup(m => m.Expression).Returns(loandata.Expression); mockSet.As <IQueryable <Product> >().Setup(m => m.ElementType).Returns(loandata.ElementType); mockSet.As <IQueryable <Product> >().Setup(m => m.GetEnumerator()).Returns(loandata.GetEnumerator()); var mockContext = new Mock <OrganizationContext>(); mockContext.Setup(c => c.Product).Returns(mockSet.Object); db = mockContext.Object; }
public async Task <IActionResult> UpdateLinkAsync([FromRoute] Guid organizationuuid, [FromBody] MapHiveUser user, [FromRoute] Guid uuid) { try { //only owners or admins should be allowed to perform this action var callerId = Cartomatic.Utils.Identity.GetUserGuid(); if (!(UserIsOrgOwner(callerId) || UserIsOrgAdmin(callerId))) { return(NotAllowed()); } //make sure user 'belongs' to an org if (!await OrganizationContext.IsOrgMemberAsync(GetDefaultDbContext(), uuid)) { return(BadRequest("Not an org user.")); } //just need to update its role within an org too user.Uuid = uuid; //in put no uuid in the model! await this.OrganizationContext.ChangeOrganizationUserRoleAsync(GetDefaultDbContext(), user); return(Ok(user)); } catch (Exception ex) { return(this.HandleException(ex)); } }
public App() { InitializeComponent(); using (var db = new OrganizationContext()) { db.Database.Migrate(); } }
public MatchPlanner(AppDb appDb, OrganizationContext organizationContext, long tournamentId) { _organizationContext = organizationContext; _appDb = appDb; _tournament = new TournamentEntity(tournamentId); _venue = new EntityCollection <VenueEntity>(new VenueEntityFactory()); _availableMatchDates = new AvailableMatchDates(_appDb, this); }
public async Task <IActionResult> DeleteAsync([FromRoute] Guid organizationuuid, [FromRoute] Guid uuid) { try { //note: //org users and org roles are modified against mh meta db! //This is where some env core objects are kept //only owners or admins should be allowed to perform this action var callerId = Cartomatic.Utils.Identity.GetUserGuid(); var callerIsOrgOwner = UserIsOrgOwner(callerId); var callerIsOrgAdmin = UserIsOrgAdmin(callerId); //only owners and admins should be able to delete users! if (!(callerIsOrgOwner || callerIsOrgAdmin)) { return(NotAllowed()); } //make sure user 'belongs' to an org if (!await OrganizationContext.IsOrgMemberAsync(GetDefaultDbContext(), uuid)) { return(BadRequest("Not an org user.")); } //make sure to prevent self deletes if (uuid == Cartomatic.Utils.Identity.GetUserGuid()) { return(BadRequest("Cannot remove self.")); } var isOrgOwner = await OrganizationContext.IsOrgOwnerAsync(GetDefaultDbContext(), uuid); if (isOrgOwner) { return(BadRequest("Cannot remove org owner.")); } var user = await Base.ReadObjAsync <MapHiveUser>(GetDefaultDbContext(), uuid); if (user == null) { return(BadRequest("No such user.")); } await user.DestroyAsync(GetDefaultDbContext()); return(Ok()); } catch (Exception ex) { return(HandleException(ex)); } }
void addEmp_Closed(object sender, EventArgs e) { EmployeeRegistrationWindow emp = (EmployeeRegistrationWindow)sender; if (emp.NewEmployee != null) { OrganizationContext _OrganizationContext = (OrganizationContext)(employeeDataSource.DomainContext); _OrganizationContext.Employees.Add(emp.NewEmployee); employeeDataSource.SubmitChanges(); } }
public static OrganizationContext Create(string connectionString) { var optionsBuilder = new DbContextOptionsBuilder <OrganizationContext>(); optionsBuilder.UseSqlServer(connectionString); // Ensure that the SQLServer database and sechema is created! var context = new OrganizationContext(optionsBuilder.Options); context.Database.EnsureCreated(); return(context); }
public PartyMemberController(PartyMemberContext context, OrganizationContext orgContext, AccountContext accContext, PartyCostContext pCContext, AccountPartyMemberContext aPMContext) { this.context = context; this.orgContext = orgContext; this.accContext = accContext; this.pCContext = pCContext; this.aPMContext = aPMContext; }
public void CloseEmailAsCancelled(Email email) { email.StateCode = EmailState.Canceled; var setStateRequest = new SetStateRequest() { Status = new OptionSetValue((int)email_statuscode.Canceled), State = new OptionSetValue((int)EmailState.Canceled), EntityMoniker = new EntityReference(Email.EntityLogicalName, email.Id) }; OrganizationContext.Execute(setStateRequest); }
public OrganizationController(OrganizationContext context) { _context = context; if (_context.OrganizationItems.Count() == 0) { // Create a new TodoItem if collection is empty, // which means you can't delete all TodoItems. _context.OrganizationItems.Add(new OrganizationItem { OrganizationName = "Item1" }); _context.SaveChanges(); } }
static async Task SeedOrganizationContext(OrganizationContext context, IServiceProvider services) { using (context) { await context.Database.EnsureCreatedAsync(); if (!context.Set <EmployeeStatus>().Any()) { var tenementTypes = Enumeration.GetAll <EmployeeStatus>(); await context.Set <EmployeeStatus>().AddRangeAsync(tenementTypes); } await context.SaveChangesAsync(); } }
public async Task <IActionResult> PutAsync([FromRoute] Guid organizationuuid, [FromBody] MapHiveUser user, [FromRoute] Guid uuid) { try { //note: //org users and org roles are modified against mh meta db! //This is where some env core objects are kept //can modify user only if org admin or owner or self var callerId = Cartomatic.Utils.Identity.GetUserGuid(); if (!(UserIsOrgOwner(callerId) || UserIsOrgAdmin(callerId) || UserIsSelf(uuid))) { return(NotAllowed()); } //make sure user 'belongs' to an org if (!await OrganizationContext.IsOrgMemberAsync(GetDefaultDbContext(), uuid)) { return(BadRequest("Not an org user.")); } //note: perhaps should disallow editing some properties such as parentOrgId, etc. var entity = await user.UpdateAsync(GetDefaultDbContext(), uuid); if (entity != null) { //once the user has been updated, need to update his role within an org too //making sure though not to change own roles. //this is so only other users with enough credentials are allowed to modify stuff such as roles if (!UserIsSelf(uuid)) { await this.OrganizationContext.ChangeOrganizationUserRoleAsync(GetDefaultDbContext(), user); } return(Ok(entity)); } return(NotFound()); } catch (Exception ex) { return(this.HandleException(ex)); } }
public HttpResponseMessage CreateOrganization([FromBody] OrganizationModel objOrg) { try { OrganizationContext objOrgContext = new OrganizationContext(); List <OrganizationModel> GetOrgList = new List <OrganizationModel>(); string result = objOrgContext.CreateOrganization(objOrg); return(Request.CreateResponse(HttpStatusCode.OK, result)); } catch (Exception ex) { //objErrorLogServices.LogError("Client", "GetClient", "", "", ex.Message.ToString()); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Internal Server Error")); } }
public async Task <IActionResult> UnLinkAsync([FromRoute] Guid organizationuuid, [FromRoute] Guid uuid) { try { //only owners or admins should be allowed to perform this action var callerId = Cartomatic.Utils.Identity.GetUserGuid(); if (!(UserIsOrgOwner(callerId) || UserIsOrgAdmin(callerId))) { return(NotAllowed()); } //note: //org users and org roles are modified against mh meta db! //This is where some env core objects are kept //get a user an make sure he is not an org user! var user = await Base.ReadObjAsync <MapHiveUser>(GetDefaultDbContext(), uuid); if (user == null) { return(BadRequest("No such user.")); } if ( (user.IsOrgUser && user.ParentOrganizationId == organizationuuid) || user.UserOrgId == organizationuuid //also avoid removing own org of a user! ) { throw MapHive.Core.DataModel.Validation.Utils.GenerateValidationFailedException(nameof(MapHiveUser), MapHive.Core.DataModel.Validation.ValidationErrors.OrgOwnerDestroyError); } //not providing a user role will effectively wipe out user assignment user.OrganizationRole = null; await this.OrganizationContext.ChangeOrganizationUserRoleAsync(GetDefaultDbContext(), user); OrganizationContext.RemoveLink(user); await OrganizationContext.UpdateAsync(GetDefaultDbContext()); return(Ok()); } catch (Exception ex) { return(HandleException(ex)); } }
/// <summary> /// Creates a new instance of the <see cref="Organization"/> object. /// </summary> /// <param name="id">The organization's ID.</param> /// <param name="auth">(Optional) Custom authorization parameters. When not provided, <see cref="TrelloAuthorization.Default"/> will be used.</param> /// <remarks> /// The supplied ID can be either the full ID or the organization's name. /// </remarks> public Organization(string id, TrelloAuthorization auth = null) { Id = id; _context = new OrganizationContext(id, auth); _context.Synchronized += Synchronized; _description = new Field <string>(_context, nameof(Description)); _displayName = new Field <string>(_context, nameof(DisplayName)); _isBusinessClass = new Field <bool>(_context, nameof(IsBusinessClass)); _name = new Field <string>(_context, nameof(Name)); _name.AddRule(OrganizationNameRule.Instance); Preferences = new OrganizationPreferences(_context.OrganizationPreferencesContext); _url = new Field <string>(_context, nameof(Url)); _website = new Field <string>(_context, nameof(Website)); _website.AddRule(UriRule.Instance); TrelloConfiguration.Cache.Add(this); }
public Task Execute(IJobExecutionContext context) { using (var scope = _provider.CreateScope()) { _uploadContext = scope.ServiceProvider.GetService <UploadContext>(); _patientContext = scope.ServiceProvider.GetService <PatientContext>(); _organizationContext = scope.ServiceProvider.GetService <OrganizationContext>(); _claimContext = scope.ServiceProvider.GetService <ClaimContext>(); _logger.LogInformation("File Processing Job Initiated: " + DateTime.Now.ToString("dddd, MMMM dd, yyyy HH:mm:ss.fffK")); List <Upload> unprocessedUploads = GetUnprocessedUploads(); _logger.LogInformation("Count of files requiring processing: " + unprocessedUploads.Count); if (unprocessedUploads.Count > 0) { ProcessFiles(unprocessedUploads); } _logger.LogInformation("File Processing Job Completed: " + DateTime.Now.ToString("dddd, MMMM dd, yyyy HH:mm:ss.fffK")); } return(Task.CompletedTask); }
public TeamInRoundValidatorTests() { #region *** Mocks *** var orgCtxMock = TestMocks.GetOrganizationContextMock(); var appDbMock = TestMocks.GetAppDbMock(); var roundsRepoMock = TestMocks.GetRepo <RoundRepository>(); roundsRepoMock .Setup(rep => rep.GetRoundsWithTypeAsync(It.IsAny <PredicateExpression>(), It.IsAny <CancellationToken>())) .Callback(() => { }).Returns((PredicateExpression filter, CancellationToken cancellationToken) => { var tournamentId = (long)((FieldCompareValuePredicate)filter[0].Contents).Value; return(Task.FromResult(new List <RoundEntity>(new [] { new RoundEntity { Id = 1, Name = "Round 1", TournamentId = tournamentId }, new RoundEntity { Id = 2, Name = "Round 2", TournamentId = tournamentId } }))); }); appDbMock.Setup(a => a.RoundRepository).Returns(roundsRepoMock.Object); var tournamentRepoMock = TestMocks.GetRepo <TournamentRepository>(); tournamentRepoMock .Setup(rep => rep.GetTournamentAsync(It.IsAny <PredicateExpression>(), It.IsAny <CancellationToken>())) .Callback(() => { }).Returns((PredicateExpression filter, CancellationToken cancellationToken) => { var tournamentId = (long)((FieldCompareValuePredicate)filter[0].Contents).Value; return(Task.FromResult(new TournamentEntity { Id = tournamentId, Name = $"Tournament{tournamentId}", Description = $"DescriptionTournament{tournamentId}" })); }); appDbMock.Setup(a => a.TournamentRepository).Returns(tournamentRepoMock.Object); orgCtxMock.SetupAppDb(appDbMock); _organizationContext = orgCtxMock.Object; _appDb = appDbMock.Object; #endregion }
/// <summary> /// Creates a new instance of the <see cref="Organization"/> object. /// </summary> /// <param name="id">The organization's ID.</param> /// <param name="auth">(Optional) Custom authorization parameters. When not provided, /// <see cref="TrelloAuthorization.Default"/> will be used.</param> /// <remarks> /// The supplied ID can be either the full ID or the organization's name. /// </remarks> public Organization(string id, TrelloAuthorization auth = null) { Id = id; _context = new OrganizationContext(id, auth); _context.Synchronized += Synchronized; Actions = new ReadOnlyActionCollection(typeof(Organization), () => Id, auth); Boards = new BoardCollection(typeof(Organization), () => Id, auth); _description = new Field <string>(_context, nameof(Description)); _displayName = new Field <string>(_context, nameof(DisplayName)); _isBusinessClass = new Field <bool>(_context, nameof(IsBusinessClass)); Members = new ReadOnlyMemberCollection(EntityRequestType.Organization_Read_Members, () => Id, auth); Memberships = new OrganizationMembershipCollection(() => Id, auth); _name = new Field <string>(_context, nameof(Name)); _name.AddRule(OrganizationNameRule.Instance); Preferences = new OrganizationPreferences(_context.OrganizationPreferencesContext); _url = new Field <string>(_context, nameof(Url)); _website = new Field <string>(_context, nameof(Website)); _website.AddRule(UriRule.Instance); TrelloConfiguration.Cache.Add(this); }
public ActionResult Login(LoginModel LoginUser) // make validation with the login user and send back the result (check in DB too). { using (OrganizationContext context = new OrganizationContext()) { var dataItem = context.Users.Where(dbuser => dbuser.UserName == LoginUser.UserName).FirstOrDefault(); if (dataItem != null) { if (IsLoginAllowed(dataItem) && dataItem.Password == LoginUser.Password) { FormsAuthentication.SetAuthCookie(dataItem.UserName, false); this.SignInUser(dataItem.UserName, false); return(RedirectToAction("Index", "home", null)); } else { if (IsLoginAllowed(dataItem)) { dataItem.FailedLoginAttempts += 1; context.SaveChanges(); ModelState.AddModelError("", "טעות בשם המשתמש או בסיסמא"); return(View()); } else { ModelState.AddModelError("", "המשתמש נעול, פנה למנהל"); return(View()); } } } else { ModelState.AddModelError("", "טעות בשם המשתמש או בסיסמא"); return(View()); } } }
public TeamValidatorTests() { #region *** Mocks *** var orgCtxMock = TestMocks.GetOrganizationContextMock(); var appDbMock = TestMocks.GetAppDbMock(); var teamRepoMock = TestMocks.GetRepo <TeamRepository>(); teamRepoMock .Setup(rep => rep.TeamNameExistsAsync(It.IsAny <TeamEntity>(), It.IsAny <CancellationToken>())) .Callback(() => { }).Returns((TeamEntity teamEntity, CancellationToken cancellationToken) => { return(Task.FromResult(teamEntity.Id < 10 ? teamEntity.Name : null)); }); appDbMock.Setup(a => a.TeamRepository).Returns(teamRepoMock.Object); orgCtxMock.SetupAppDb(appDbMock); _organizationContext = orgCtxMock.Object; _appDb = appDbMock.Object; #endregion }
public async Task <IActionResult> Get([FromRoute] Guid organizationuuid, [FromQuery] string sort = null, [FromQuery] string filter = null, [FromQuery] int start = 0, [FromQuery] int limit = 25) { try { //Note: //main mh env objects are kept in the maphive_meta db! var apps = await OrganizationContext.GetOrganizationLinkableAppsAsync(GetDefaultDbContext(), sort, filter, start, limit); if (apps != null) { HttpContext.AppendTotalHeader(apps?.count ?? 0); return(Ok(apps?.applications)); } return(NotFound()); } catch (Exception ex) { return(this.HandleException(ex)); } }
public DashboardController(PatientContext patientContext, OrganizationContext organizationContext, ClaimContext claimContext) { _patientContext = patientContext; _organizationContext = organizationContext; _claimContext = claimContext; }
public OrganizationController(OrganizationContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public OrganizationRepository(OrganizationContext context) { this.context = context; context.Database.EnsureCreated(); this.DBSet = this.context.Set <T>(); }
public DocumentService(OrganizationContext context, ApplicationSettings applicationSettings) { _context = context; _applicationSettings = applicationSettings; }
public HomeController(OrganizationContext context) { _context = context; }
public EmployeesController(OrganizationContext db) { _db = db; }