public IHttpActionResult PutiMentorUser(int id, iMentorUser iMentorUser) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != iMentorUser.Id) { return BadRequest(); } db.Entry(iMentorUser).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!iMentorUserExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public int GetRoleIdByUser(iMentorUser user) { using (iMAST_dbEntities db = new iMAST_dbEntities()) { var userRole = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault(); var result = userRole.RoleId; return result; } }
public IHttpActionResult PostiMentorUser(iMentorUser iMentorUser) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.iMentorUsers.Add(iMentorUser); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = iMentorUser.Id }, iMentorUser); }
public string GetRoleName(iMentorUser user) { using (iMAST_dbEntities db = new iMAST_dbEntities()) { var userRole = db.iMentorUserRoles.Where(x => x.UserId == user.Id).FirstOrDefault(); var role = db.iMentorRoles.Where(x => x.Id == userRole.RoleId).FirstOrDefault(); var result = role.RoleName; return result; } }
public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl) { if (User.Identity.IsAuthenticated) { return RedirectToAction("Index", "Manage"); } if (ModelState.IsValid) { // Get the information about the user from the external login provider var info = await AuthenticationManager.GetExternalLoginInfoAsync(); if (info == null) { return View("ExternalLoginFailure"); } var user = new ApplicationUser { UserName = model.Email, Email = model.Email }; var result = await UserManager.CreateAsync(user); if (result.Succeeded) { //Create the iMentorUser entry using (iMAST_dbEntities db = new iMAST_dbEntities()) { bool userExists = false; foreach (iMentorUser u in db.iMentorUsers.ToList()) { if (u.Email.Equals(user.Email)) { userExists = true; } } //Create the user if (!userExists) { var imUser = new iMentorUser(); imUser.UserName = user.UserName; imUser.Email = user.Email; imUser.UrlId = GetNewUrlId(); db.iMentorUsers.Add(imUser); db.SaveChanges(); //Create the Role var imUserRole = new iMentorUserRole(); imUserRole.UserId = imUser.Id; imUserRole.RoleId = db.iMentorRoles.Where(x => x.RoleName.Equals("Read Only")).FirstOrDefault().Id; //Default role is "Read Only" db.iMentorUserRoles.Add(imUserRole); db.SaveChanges(); } } result = await UserManager.AddLoginAsync(user.Id, info.Login); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); return RedirectToAction("Index", "Home"); } } AddErrors(result); } //ViewBag.ReturnUrl = returnUrl; //return View(model); return RedirectToAction("Index", "Home"); }