public StaffAssignmentInfo(AccountRole accountRole) { stranddContext context = new stranddContext(); AccountRole returnAccountRole = accountRole; if (returnAccountRole != null) { this.UserProviderID = returnAccountRole.UserProviderID; this.RoleAssignment = returnAccountRole.RoleAssignment; Account returnUser = context.Accounts .Where(u => u.ProviderUserID == returnAccountRole.UserProviderID) .FirstOrDefault(); if (returnUser != null) { this.AccountGUID = returnUser.Id; this.Name = returnUser.Name; this.Phone = returnUser.Phone; this.Email = returnUser.Email; } else { this.Name = "NONE"; this.Phone = "NONE"; this.Email = "NONE"; } Company returnCompany = context.Companies .Where(u => u.Id == returnAccountRole.CompanyGUID) .FirstOrDefault(); if (returnCompany != null) { this.CompanyName = returnCompany.Name; } else { this.CompanyName = "NONE"; } } else { this.RoleAssignment = "NONE"; this.CompanyName = "NONE"; } }
public async Task<HttpResponseMessage> NewStaffAssignment(AccountRoleRequest accountRoleRequest) { Services.Log.Info("New Staff Assignment Request [API]"); string responseText; stranddContext context = new stranddContext(); //Checks for existing Link References Account lookupAccount = await context.Accounts.Where(a => a.ProviderUserID == accountRoleRequest.UserProviderID).SingleOrDefaultAsync(); Company lookupCompany = await context.Companies.Where(a => a.Id == accountRoleRequest.CompanyGUID).SingleOrDefaultAsync(); if (lookupAccount == null) { responseText = "Account not found [" + accountRoleRequest.UserProviderID + "]"; Services.Log.Warn(responseText); return this.Request.CreateResponse(HttpStatusCode.BadRequest, responseText); } if (lookupCompany == null) { responseText = "Company not found [" + accountRoleRequest.CompanyGUID + "]"; Services.Log.Warn(responseText); return this.Request.CreateResponse(HttpStatusCode.BadRequest, responseText); } if (accountRoleRequest.RoleAssignment == null) { responseText = "No Role Assignment Defined"; Services.Log.Warn(responseText); return this.Request.CreateResponse(HttpStatusCode.BadRequest, responseText); } AccountRole lookupAccountRole = await context.AccountRoles.Where(a => a.UserProviderID == accountRoleRequest.UserProviderID) .Where(b => b.CompanyGUID == accountRoleRequest.CompanyGUID) .Where(c => c.RoleAssignment == accountRoleRequest.RoleAssignment).SingleOrDefaultAsync(); if (lookupAccountRole == null) { //Staff Assignment Creation AccountRole newAccountRole = new AccountRole { Id = Guid.NewGuid().ToString(), RoleAssignment = accountRoleRequest.RoleAssignment, CompanyGUID = accountRoleRequest.CompanyGUID, UserProviderID = accountRoleRequest.UserProviderID }; context.AccountRoles.Add(newAccountRole); await context.SaveChangesAsync(); responseText = "Staff Assignment Successfully Generated"; Services.Log.Info(responseText); return this.Request.CreateResponse(HttpStatusCode.Created, responseText); } else { responseText = "Staff Assignment Already Exists"; Services.Log.Info(responseText); return this.Request.CreateResponse(HttpStatusCode.OK, responseText); } }
public async Task<IHttpActionResult> GetCurrentAccountRoles(string companyGUID) { List<AccountRole> dbRoleCollection = new List<AccountRole>(); // Get the logged-in user. var currentUser = this.User as ServiceUser; Services.Log.Info("Find Company [" + companyGUID + "] Staff Assignments for Current User"); stranddContext context = new stranddContext(); //Loading List of Account Roles from DB Context dbRoleCollection = await context.AccountRoles.Where(a => a.UserProviderID == currentUser.Id) .Where(b => b.CompanyGUID == companyGUID).ToListAsync<AccountRole>(); if (dbRoleCollection.Count > 0) { string responseText = "Returned Company [" + companyGUID + "] Staff Assignments for Account [" + currentUser.Id + "] " + currentUser.Id; Services.Log.Info(responseText); return Ok(dbRoleCollection); } else { string responseText = "No Company [" + companyGUID + "] Staff Assignments for Account [" + currentUser.Id + "] " + currentUser.Id; Services.Log.Info(responseText); AccountRole noneRole = new AccountRole { CompanyGUID = companyGUID, RoleAssignment = "NONE", UserProviderID = currentUser.Id }; dbRoleCollection.Add(noneRole); return Ok(dbRoleCollection); } }