public async Task<bool> AddUser(UserAddRequest request)
 {
     try
     {
         HttpResponseMessage httpResp = apiCom.executePostAPI("User", JsonConvert.SerializeObject(request));
         if (httpResp.IsSuccessStatusCode)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
     catch
     {
         return false;
     }
 }
        public DomainModelResponse Add(UserAddRequest request)
        {
            EntityModel.Role role = _repRole.Get(filter: f => f.RoleCode == request.RoleCode).FirstOrDefault();

            UserProfile up = new UserProfile()
            {
                EmailId = request.emailId,
                FirstName = request.firstName,
                LastName = request.lastName,
                HashedPassword = createHash(request.password),
                SecurityQuestion = request.securityQuestion,
                HashedAnswer = createHash(request.answer),
                isAdmin = request.isAdmin,
                LastChangedTime = DateTime.UtcNow,
                LastPasswordChangeDate = DateTime.UtcNow,
                PasswordExpired = false,
                CourseUserRoles = null
            };
            _repUser.Add(up);
            _uow.Commit();
            AddUserToCourse(new UpdateUserCourse() { courseCode = "Default", emailId = request.emailId, RoleCode = request.RoleCode });
            _securityResponse.addResponse("Add", MessageCodes.InfoCreatedSuccessfully, "User");
            return _securityResponse;
        }
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                UserAddRequest user = new UserAddRequest()
                {
                    firstName = model.FirstName,
                    lastName = model.LastName,
                    emailId = model.Email,
                    password = model.Password,
                    securityQuestion = model.SecurityQuestion,
                    answer = model.SecurityAnswer,
                    RoleCode = model.Role.ToString(),
                    isAdmin = model.Role == Models.Role.Admin ? true : false
                };

                bool result = _userCom.AddUser(user).Result;
                if(result)//User is added
                {
                    return RedirectToAction("Login", "Account");
                }
                
                //var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
                //var result = await UserManager.CreateAsync(user, model.Password);
                //if (result.Succeeded)
                //{
                //    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
            AddErrors(new IdentityResult("Oops! Something wrong happened! Please try again."));
            return View(model);
        }