public IHttpActionResult PutAIAUser(int id, AIAUser aIAUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != aIAUser.Id) { return(BadRequest()); } db.Entry(aIAUser).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!AIAUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public void CreateAIAAccount(string userName, string firstName, string lastName, string userId) { AIAUser user = new AIAUser { UserName = userName, FirstName = firstName, LastName = lastName, ApplicationUserId = userId, CanUseSystem = 1 }; db.AIAUsers.Add(user); db.SaveChanges(); }
public void Register() { AIAUser newUser = new AIAUser(); newUser.FirstName = registrationViewModel.FirstName; newUser.LastName = registrationViewModel.LastName; newUser.UserName = registrationViewModel.UserName; newUser.CanUseSystem = 0; Helper.Post <AIAUser>(newUser); }
public IHttpActionResult GetAIAUser(int id) { AIAUser aIAUser = db.AIAUsers.Find(id); if (aIAUser == null) { return(NotFound()); } return(Ok(aIAUser)); }
public async Task <ActionResult> RegisterManager(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.UserName, Email = model.Email }; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { UserManager.AddToRole(user.Id, "Manager"); var db = new ApplicationDbContext(); var aiaUser = new AIAUser { FirstName = model.FirstName, LastName = model.Lastname, ApplicationUserId = user.Id, UserName = model.UserName, CanUseSystem = 0 }; db.AIAUsers.Add(aiaUser); try { db.SaveChanges(); } catch (DbEntityValidationException ex) { // Retrieve the error messages as a list of strings. var errorMessages = ex.EntityValidationErrors .SelectMany(x => x.ValidationErrors) .Select(x => x.ErrorMessage); // Join the list to a single string. var fullErrorMessage = string.Join("; ", errorMessages); // Combine the original exception message with the new one. var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); } //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return(RedirectToAction("Index", "Home")); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public IHttpActionResult PostAIAUser(AIAUser aIAUser) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.AIAUsers.Add(aIAUser); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = aIAUser.Id }, aIAUser)); }
public ActionResult UpdateUser(AIAUser model) { var user = db.AIAUsers.SingleOrDefault(u => u.Id == model.Id); if (user == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } user.CanUseSystem = model.CanUseSystem; db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
// GET: Users public ActionResult Index() { AIAUser u = new AIAUser(); u.FirstName = "Hari"; u.LastName = "Hari"; u.CanUseSystem = 1; u.UserName = "******"; AIAUser ans = Helper.Post(u); return(View()); }
public IHttpActionResult DeleteAIAUser(int id) { AIAUser aIAUser = db.AIAUsers.Find(id); if (aIAUser == null) { return(NotFound()); } db.AIAUsers.Remove(aIAUser); db.SaveChanges(); return(Ok(aIAUser)); }