public ClientUserDetails GetClient(Guid id) { ClientUserDetails client = _db.Clients .Include("ApplicationUser") // .Include("Artist") // .Include("Genre") .SingleOrDefault(i => i.Id == id); return(client); }
public bool AddClient(ClientUserDetails client) { if (client == null) { throw new ArgumentNullException(); } client.Id = Guid.NewGuid(); _db.Clients.Add(client); return(Save()); }
public bool UpdateClient(ClientUserDetails client) { if (client == null) { throw new ArgumentNullException(); } //_db.Clients.Attach(vm.Client); //// it should be vm (not vm.Client) //_db.Entry(vm.Client).State = EntityState.Modified; //_db.SaveChanges(); _db.Clients.Update(client); return(Save()); }
public IActionResult Create([FromBody] ClientUserDetails ClientUserDetails) { if (ClientUserDetails == null) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_client.AddClient(ClientUserDetails)) { ModelState.AddModelError("", "Something went wrong."); return(StatusCode(500, ModelState)); } return(CreatedAtRoute("Client", new { id = ClientUserDetails.Id }, ClientUserDetails)); }
public IActionResult DeleteClient([FromBody] ClientUserDetails clientToDelete) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (clientToDelete == null) { ModelState.AddModelError("", "Can't find client."); return(StatusCode(500, ModelState)); } if (!_client.DeleteClient(clientToDelete)) { ModelState.AddModelError("", "Something went wrong deleting client."); return(StatusCode(500, ModelState)); } return(NoContent()); }
public IActionResult UpdateClient(Guid id, [FromBody] ClientUserDetails updatedClientUserDetails) { if (updatedClientUserDetails == null) { return(BadRequest(ModelState)); } if (id != updatedClientUserDetails.Id) { return(BadRequest(ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_client.UpdateClient(updatedClientUserDetails)) { ModelState.AddModelError("", "Something went wrong updating client."); return(StatusCode(500, ModelState)); } return(NoContent()); }
public bool DeleteClient(ClientUserDetails client) { _db.Clients.Remove(client); return(Save()); }
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()); }