public async Task <IActionResult> PutUserRole(int id, UserRole UserRole)
        {
            if (id != UserRole.Id)
            {
                return(BadRequest());
            }

            _context.Entry(UserRole).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!UserRoleExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutAppUser(int id, AppUser appUser)
        {
            if (id != appUser.Id)
            {
                return(BadRequest());
            }

            try
            {
                var appUserToUpdate = await _context.AppUser.Where(au => au.Id == id).FirstOrDefaultAsync();

                appUserToUpdate.Id             = appUser.Id;
                appUserToUpdate.NetworkId      = appUser.NetworkId;
                appUserToUpdate.DisplayName    = appUser.DisplayName;
                appUserToUpdate.CompanyName    = appUser.CompanyName;
                appUserToUpdate.UserRoleId     = appUser.UserRoleId;
                appUserToUpdate.IsActive       = appUser.IsActive;
                appUserToUpdate.CreatedBy      = appUser.CreatedBy;
                appUserToUpdate.CreatedOn      = appUser.CreatedOn;
                appUserToUpdate.LastModifiedBy = await _context.AppUser.Where(au => au.NetworkId == HttpContext.User.Identity.Name).Select(appu => appu.Id).FirstOrDefaultAsync();

                appUserToUpdate.LastModifiedDate = DateTime.Now;
                appUserToUpdate.LastLoggedInDate = appUser.LastLoggedInDate;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AppUserExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                string errMsg = string.Empty;

                if (_environment.EnvironmentName == "Production")
                {
                    errMsg = string.Format("Error saving app user changes to database.");
                }
                else // detailed error message for DEV and TST environments
                {
                    errMsg = string.Format("Error saving app user changes to database: {0} Inner Exception: {1}.", ex.Message, ex.InnerException);
                }

                return(BadRequest(new { error = errMsg }));
            }

            return(Ok(appUser));
        }