public void Add() { Administrator administrator = new Administrator(auth); try { AdministratorDetails administratorDetails = new AdministratorDetails { EmailAddress = "*****@*****.**", Name = "test", }; administrator.Add(administratorDetails); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { // Handle some other failure Console.WriteLine(ex.ToString()); } }
public bool UpdateAdministrator(AdministratorDetails administratorUser) { if (administratorUser == null) { return(false); } _db.Administrators.Update(administratorUser); return(Save()); }
public bool AddAdministrator(AdministratorDetails administratorUser) { if (administratorUser == null) { throw new ArgumentNullException(); } administratorUser.Id = Guid.NewGuid(); _db.Administrators.Add(administratorUser); return(Save()); }
internal static KeyVaultCertificateAdministratorDetails FromAdministratorDetails(AdministratorDetails administratorDetails) { if (administratorDetails == null) { return null; } return new KeyVaultCertificateAdministratorDetails { FirstName = administratorDetails.FirstName, LastName = administratorDetails.LastName, EmailAddress = administratorDetails.EmailAddress, PhoneNumber = administratorDetails.Phone, }; }
public bool DeleteAdministrator(AdministratorDetails admin) { // Auto einai gia kanoume delete me vash to Id tou // var deletedAdministrator = _db.Administrators.SingleOrDefault(m => m.AdminId == id); // if (deletedAdministrator == null) // { // // return false; // } // else // { // _db.Administrators.Remove(deletedAdministrator); // return Save(); // } _db.Administrators.Remove(admin); return(Save()); }
public IActionResult Create([FromBody] AdministratorDetails adminCreated) { if (adminCreated == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest()); } if (!_administratorDetailsRepository.AddAdministrator(adminCreated)) { ModelState.AddModelError("", "Something went wrong."); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("Admin", new { id = adminCreated.Id }, adminCreated)); }
public IActionResult DeleteAdmin([FromBody] AdministratorDetails adminToDelete) { if (!ModelState.IsValid) { return(BadRequest()); } if (adminToDelete == null) { ModelState.AddModelError("", "Can't find admin."); return(StatusCode(500, ModelState)); } if (!_administratorDetailsRepository.DeleteAdministrator(adminToDelete)) { ModelState.AddModelError("", "Something went wrong deleting client."); return(StatusCode(500, ModelState)); } return(NoContent()); }
public void Update() { Administrator administrator = new Administrator(auth); try { AdministratorDetails administratorDetails = administrator.Details("*****@*****.**"); administratorDetails.Name = "test new name"; administrator.Update("*****@*****.**", administratorDetails); } catch (CreatesendException ex) { ErrorResult error = (ErrorResult)ex.Data["ErrorResult"]; Console.WriteLine(error.Code); Console.WriteLine(error.Message); } catch (Exception ex) { // Handle some other failure Console.WriteLine(ex.ToString()); } }
public IActionResult UpdateAdmin(Guid id, [FromBody] AdministratorDetails adminCreated) { if (adminCreated == null) { return(BadRequest(ModelState)); } if (id != adminCreated.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_administratorDetailsRepository.UpdateAdministrator(adminCreated)) { ModelState.AddModelError("", "Something went wrong updating Admin."); return(StatusCode(500, ModelState)); } return(NoContent()); }
internal static KeyVaultCertificateAdministratorDetails FromAdministratorDetails(AdministratorDetails administratorDetails) { if (administratorDetails == null) { return(null); } return(new KeyVaultCertificateAdministratorDetails { FirstName = administratorDetails.FirstName, LastName = administratorDetails.LastName, EmailAddress = administratorDetails.EmailAddress, PhoneNumber = administratorDetails.Phone, }); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new ApplicationUser { FirstName = Input.FirstName, LastName = Input.LastName, UserName = Input.Email, Email = Input.Email, UserRole = Input.UserRole }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var userId = _userManager.Users.SingleOrDefault(i => i.Email == user.Email).Id; var role = Input.UserRole; switch (role) { case "Client": if (userId != null) { var client = new ClientUserDetails { ApplicationUserId = userId }; _clientRepository.AddClient(client); } break; case "Mentor": if (userId != null) { var mentor = new MentorUserDetails { ApplicationUserId = userId }; _mentorRepository.AddMentor(mentor); } break; case "HR": if (userId != null) { var HR = new HrUserDetails { ApplicationUserId = userId }; _hrRepository.AddHr(HR); } break; case "Admin": if (userId != null) { var admin = new AdministratorDetails { ApplicationUserId = userId }; _administratorDetailsRepository.AddAdministrator(admin); } break; } var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); //Προσθέτω μετά το Register το User στο Role εγγραφή στον ενδιάμεσο πίνακα Σπυροσσ await _userManager.AddToRoleAsync(user, Input.UserRole); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email })); } else { await _signInManager.SignInAsync(user, isPersistent : false); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError("Error", error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }