private string GenerateJWTToken(TabAdmin userinfo, TaxiAppzDBContext context) { try { insertlog("Token Generation", userinfo.Email, "GenerateJWTToken", context); var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwt.SecretKey)); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, userinfo.Firstname), new Claim("lastName", userinfo.Lastname), new Claim("role", userinfo.RoleNavigation.RoleName), new Claim("MailID", userinfo.Email), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()), }; var token = new JwtSecurityToken( issuer: _jwt.Issuer, audience: _jwt.Audience, claims: claims, expires: DateTime.Now.AddMinutes(_jwt.AccessTokenDuration), signingCredentials: credentials ); return(new JwtSecurityTokenHandler().WriteToken(token)); } catch (Exception ex) { insertlog(ex.Message, userinfo.Email, "GenerateJWTToken", context); return(null); } }
public void ClickTabAdmin() { VisibilityOfAllElementsLocatedBy(By.Id("_externalPage"), 10); TabAdmin.Click(); WaitForPageUntilElementIsVisible(By.LinkText("Scripts"), 10); TabObject.Click(); }
public bool Save(TaxiAppzDBContext context, AdminDetails adminDetails, LoggedInUser loggedInUser) { var emailid = context.TabAdmin.FirstOrDefault(t => t.IsDeleted == 0 && t.Email.ToLower() == adminDetails.Email.ToLower() && t.Id != adminDetails.Id); if (emailid != null) { throw new DataValidationException($"Email id '{emailid.Email}' already exists."); } var service = context.TabServicelocation.FirstOrDefault(t => t.IsDeleted == 0 && t.Servicelocid == adminDetails.Area); if (service == null) { throw new DataValidationException($"Service location does not exists."); } var role = context.TabRoles.FirstOrDefault(t => t.IsDelete == 0 && t.Roleid == adminDetails.RoleId); if (role == null) { throw new DataValidationException($"Role already not exists."); } TabAdmin tabAdmin = new TabAdmin(); tabAdmin.AdminKey = ""; tabAdmin.AdminReference = 0; tabAdmin.AreaName = adminDetails.Area; tabAdmin.Email = adminDetails.Email.ToLower(); tabAdmin.EmergencyNumber = adminDetails.Emerphonenumber; tabAdmin.Firstname = adminDetails.Firstname; tabAdmin.Language = adminDetails.Languagename; tabAdmin.Lastname = adminDetails.Lastname; tabAdmin.Password = adminDetails.Password; tabAdmin.PhoneNumber = adminDetails.Phonenumber; tabAdmin.ProfilePic = adminDetails.ProfilePicture; tabAdmin.RegistrationCode = (context.TabAdmin.Count() + 1).ToString(); tabAdmin.Role = adminDetails.RoleId; tabAdmin.IsActive = 1; tabAdmin.IsDeleted = 0; tabAdmin.CreatedAt = DateTime.UtcNow; tabAdmin.UpdatedAt = DateTime.UtcNow; tabAdmin.UpdatedBy = tabAdmin.CreatedBy = loggedInUser.Email; context.TabAdmin.Add(tabAdmin); context.SaveChanges(); TabAdminDetails tabAdminDetails = new TabAdminDetails(); tabAdminDetails.AdminId = tabAdmin.Id; tabAdminDetails.Address = adminDetails.Address; tabAdminDetails.PostalCode = adminDetails.Postalcode; tabAdminDetails.CountryId = adminDetails.Country; context.TabAdminDetails.Add(tabAdminDetails); context.SaveChanges(); return(true); }
public bool Edit(TaxiAppzDBContext context, AdminDetails adminDetails, LoggedInUser loggedInUser) { var admin = context.TabAdmin.FirstOrDefault(t => t.IsDeleted == 0 && t.Id == adminDetails.Id); if (admin != null) { throw new DataValidationException($"Admin does not exists"); } var emailid = context.TabAdmin.FirstOrDefault(t => t.IsDeleted == 0 && t.Email.ToLower() == adminDetails.Email.ToLower() && t.Id != adminDetails.Id); if (emailid != null) { throw new DataValidationException($"Email id '{emailid.Email}' already exists."); } var service = context.TabServicelocation.FirstOrDefault(t => t.IsDeleted == 0 && t.Servicelocid == adminDetails.Area); if (emailid != null) { throw new DataValidationException($"Email id '{emailid.Email}' already exists."); } var tabAdmin = context.TabAdmin.Include(t => t.TabAdminDetails).Where(r => r.Id == adminDetails.Id && r.IsDeleted == 0).FirstOrDefault(); if (tabAdmin != null) { tabAdmin.AreaName = adminDetails.Area; tabAdmin.Email = adminDetails.Email; tabAdmin.EmergencyNumber = adminDetails.Emerphonenumber; tabAdmin.Firstname = adminDetails.Firstname; tabAdmin.Language = adminDetails.Languagename; tabAdmin.Lastname = adminDetails.Lastname; tabAdmin.PhoneNumber = adminDetails.Phonenumber; tabAdmin.ProfilePic = adminDetails.ProfilePicture; tabAdmin.Role = adminDetails.RoleId; tabAdmin.UpdatedAt = DateTime.UtcNow; tabAdmin.UpdatedBy = loggedInUser.Email; context.TabAdmin.Update(tabAdmin); context.SaveChanges(); } else { TabAdmin tab = new TabAdmin(); tab.AreaName = adminDetails.Area; tab.Email = adminDetails.Email; tab.EmergencyNumber = adminDetails.Emerphonenumber; tab.Firstname = adminDetails.Firstname; tab.Language = adminDetails.Languagename; tab.Lastname = adminDetails.Lastname; tab.Password = adminDetails.Password; tab.PhoneNumber = adminDetails.Phonenumber; tab.ProfilePic = adminDetails.ProfilePicture; tab.Role = adminDetails.RoleId; tab.UpdatedAt = DateTime.UtcNow; tab.UpdatedBy = loggedInUser.Email; context.TabAdmin.Add(tab); context.SaveChanges(); } var tabAdmindetails = context.TabAdminDetails.Where(r => r.AdminId == adminDetails.Id && r.IsDeleted == 0).FirstOrDefault(); if (tabAdmindetails != null) { tabAdmindetails.AdminId = tabAdmin.Id; tabAdmindetails.Address = adminDetails.Address; tabAdmindetails.PostalCode = adminDetails.Postalcode; tabAdmindetails.CountryId = adminDetails.Country; tabAdmindetails.UpdatedAt = DateTime.UtcNow; tabAdmindetails.UpdatedBy = loggedInUser.Email; context.TabAdminDetails.Update(tabAdmindetails); context.SaveChanges(); } else { TabAdminDetails details = new TabAdminDetails(); details.AdminId = tabAdmin.Id; details.Address = adminDetails.Address; details.PostalCode = adminDetails.Postalcode; details.CountryId = adminDetails.Country; details.UpdatedAt = DateTime.UtcNow; details.UpdatedBy = loggedInUser.Email; context.TabAdminDetails.Add(details); context.SaveChanges(); } return(true); }