public void SaveUsers()
        {
            var users = new UserTable
            {
                FirstName  = "NUNIT",
                LastName   = "NUNIT",
                EmployeeId = 3,
                Deleted    = false
            };

            bool added = user.Add(users);

            Assert.AreEqual(true, added);
        }
Example #2
0
 public IHttpActionResult AddUser(UserTable Users)
 {
     if (ModelState.IsValid)
     {
         try
         {
             bl.Add(Users);
         }
         catch (Exception)
         {
             return(Ok("Error is occured during inserted !"));
         }
         return(Ok("Record is added Sucessfully !"));
     }
     return(Ok());
 }
Example #3
0
 public async Task <ActionResult> AddUser(UserViewModel uvm)
 {
     if (ModelState.IsValid)
     {
         userinfo user = new userinfo();
         user.username = uvm.username;
         user.password = UserBusinessLayer.GetMD5(uvm.password);
         user.rights   = "user";
         UserBusinessLayer ubl = new UserBusinessLayer();
         if (await ubl.Add(user))
         {
             return(RedirectToAction("Login"));
         }
         else
         {
             ViewBag.errorMsg = "用户名已存在";
             return(View("Register"));
         }
     }
     else
     {
         return(View("Register", uvm));
     }
 }
Example #4
0
        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)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        //Assign Role to user Here
                        await this.UserManager.AddToRoleAsync(user.Id, model.UserRole);

                        //Ends Here
                        //
                        // Add user to user table
                        //
                        User newUser = new User();
                        newUser.Active       = 1;
                        newUser.EmailAddress = model.Email;
                        newUser.Id           = user.Id;
                        newUser.Role         = model.UserRole;
                        UserBusinessLayer ubl = new UserBusinessLayer();
                        ubl.Add(newUser);

                        switch (model.UserRole)
                        {
                        case "Amateur Artist":
                            Artist newArtist = new Artist();
                            newArtist.UserID = newUser.UserID;
                            ArtistBusinessLayer abl = new ArtistBusinessLayer();
                            abl.Add(newArtist);
                            break;

                        case "Business Owner":
                            Business newBusiness = new Business();
                            newBusiness.UserID = newUser.UserID;
                            BusinessBusinessLayer bbl = new BusinessBusinessLayer();
                            bbl.Add(newBusiness);
                            break;

                        default:
                            // Admin Role??
                            break;
                        }


                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }