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 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();
 }
        // 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 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);
 }