public virtual IActionResult UserDistrictsIdSwitchPost([FromRoute] int id) { bool exists = _context.HetUserDistrict.Any(a => a.UserDistrictId == id); // not found if (!exists) { return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration)))); } // get record HetUserDistrict userDistrict = _context.HetUserDistrict.First(a => a.UserDistrictId == id); string userId = UserAccountHelper.GetUserId(_httpContext); HetUser user = _context.HetUser.First(a => a.SmUserId == userId); user.DistrictId = userDistrict.DistrictId; _context.SaveChanges(); // create new district switch cookie _httpContext.Response.Cookies.Append( "HETSDistrict", userDistrict.DistrictId.ToString(), new CookieOptions { Path = "/", SameSite = SameSiteMode.None } ); return(new ObjectResult(new HetsResponse(user))); }
private bool CanAccessOwner(int businessId, int ownerId) { // validate that the current user can access this record string userId = UserAccountHelper.GetUserId(_httpContext); bool isBusiness = UserAccountHelper.IsBusiness(_httpContext); // not a business user if (string.IsNullOrEmpty(userId) || !isBusiness) { return(false); } // get business & owner record HetOwner owner = _context.HetOwner.AsNoTracking() .Include(x => x.Business) .ThenInclude(x => x.HetBusinessUser) .FirstOrDefault(x => x.BusinessId == businessId && x.OwnerId == ownerId); // get user HetBusinessUser user = owner?.Business?.HetBusinessUser .FirstOrDefault(x => x.BceidUserId.Equals(userId, StringComparison.InvariantCultureIgnoreCase)); // no access to business or business doesn't exist return(user != null); }
public virtual IActionResult UserDistrictsGet() { // return for the current user only string userId = UserAccountHelper.GetUserId(_httpContext); List <HetUserDistrict> result = _context.HetUserDistrict.AsNoTracking() .Include(x => x.User) .Include(x => x.District) .Where(x => x.User.SmUserId == userId) .ToList(); return(new ObjectResult(new HetsResponse(result))); }