示例#1
0
        public async void TestAuthenticate_Return_NotOkResult(AuthenticateRequest model, string description)
        {
            var user = new AppUser
            {
                Email          = model.Email,
                UserName       = model.UserName,
                EmailConfirmed = true,
                RefreshTokens  = new List <RefreshToken>(),
                Id             = Guid.NewGuid().ToString()
            };

            var password = "******";

            fakeUserManager.Setup(x => x.FindByEmailAsync(user.Email)).Returns(Task.FromResult(users.FirstOrDefault <AppUser>(u => u.Email == user.Email) == null ? null : user));
            fakeUserManager.Setup(x => x.FindByNameAsync(user.UserName)).Returns(Task.FromResult(users.FirstOrDefault <AppUser>(u => u.UserName == user.UserName) == null ? null : user));
            fakeSignInManager.Setup(x => x.CheckPasswordSignInAsync(It.IsAny <AppUser>(), It.IsAny <String>(), false)).ReturnsAsync(password.Equals(model.Password) == true ? SignInResult.Success : SignInResult.Failed);

            context.Add(user);
            context.SaveChanges();


            var data = await _userService.Object.Authenticate(model);

            Assert.IsType <BadRequestObjectResult>(data);
        }
        public async Task <IActionResult> GetOrCreateUserByPhone(string phone)
        {
            //筛选条件
            if (string.IsNullOrWhiteSpace(phone))
            {
                return(BadRequest());
            }
            else
            {
                var userMod = await _userDbContext.ClientUser.AsNoTracking().FirstOrDefaultAsync(user => user.PhoneNumber == phone);

                if (userMod == null)
                {
                    userMod = new ClientUser {
                        PhoneNumber = phone, ClientUserCode = phone, Password = phone
                    };
                    _userDbContext.Add(userMod);
                    _userDbContext.SaveChanges();
                }
                var userBasicInfo = await _userDbContext.ClientUser_BasicInfo.AsNoTracking().FirstOrDefaultAsync(user => user.ClientUserId == userMod.Id);

                if (userBasicInfo == null)
                {
                    userBasicInfo = new ClientUser_BasicInfo {
                        ClientUserId = userMod.Id, CreateTime = DateTime.Now
                    };
                    _userDbContext.Add(userBasicInfo);
                    _userDbContext.SaveChanges();
                }
                var roletype  = AdminRoleType.Vacationer;
                var role_user = await _userDbContext.AdminRole_ClientUserBasicInfo.AsNoTracking().FirstOrDefaultAsync(ru => ru.UserBasicInfoId == userBasicInfo.Id);

                if (role_user != null)
                {
                    var role = await _userDbContext.AdminRole.AsNoTracking().FirstOrDefaultAsync(r => r.Id == role_user.RoleId);

                    if (role != null)
                    {
                        roletype = role.RoleType;
                    }
                }
                return(Ok(new UserIdentityInfo
                {
                    UserId = userMod.Id,
                    UserBasicInfoId = userBasicInfo.Id,
                    UserName = userBasicInfo.ClientUserName,
                    RoleType = roletype
                }));
            }
        }
        public async Task <User> AddAsync(User user)
        {
            context.Add(user);
            await context.SaveChangesAsync();

            return(user);
        }
示例#4
0
        public int CreateAccountStatistic(AccountStatistic accountStatistic)
        {
            _context.Add(accountStatistic);
            _context.SaveChanges();

            return(accountStatistic.Id);
        }
示例#5
0
        public async Task <User> CreateAsync(User user)
        {
            _context.Add(user);
            await _context.SaveChangesAsync();

            return(user);
        }
示例#6
0
        public int AddEquipment(EquipmentOwned equipmentOwned)
        {
            _context.Add(equipmentOwned);
            _context.SaveChanges();

            return(equipmentOwned.Id);
        }
示例#7
0
 private void Save_Button_Click(object sender, RoutedEventArgs e)
 {
     if (nameTextBox.Text != "" && priceTextBox.Text != "" && stockTextBox.Text != "" && EANTextBox.Text != "")
     {
         Inventory inventory = new Inventory()
         {
             ItemName        = nameTextBox.Text,
             ItemPrice       = priceTextBox.Text,
             ItemStockNumber = stockTextBox.Text,
             ItemEANNumber   = EANTextBox.Text,
             ItemDescription = DescriptionTextBox.Text
         };
         context.Add <Inventory>(inventory);
         context.SaveChanges();
         MessageBox.Show("Data saved");
         nameTextBox.Text        = "";
         priceTextBox.Text       = "";
         stockTextBox.Text       = "";
         EANTextBox.Text         = "";
         DescriptionTextBox.Text = "";
     }
     else
     {
         MessageBox.Show("Please fill all the fields.");
     }
 }
示例#8
0
        public bool AddUser(UserDto userDto)
        {
            try
            {
                string email = userDto.Email.ToString();
                flag = false;
                var isExists = UserExists(email);

                if (isExists == null)
                {
                    var userModel = _mapper.Map <UserModel>(userDto);
                    userModel.Role = "Customer";
                    _user.Add(userModel);
                    _user.SaveChanges();
                    flag = true;
                    return(flag);
                }
                else
                {
                    flag = false;
                    return(flag);
                }
            }
            catch
            {
                return(false);
            }
        }
示例#9
0
        public Payment[] AddPayments(Payment[] payments)
        {
            Payment[] paymentsArray = payments;

            _db.Add(payments);
            _db.SaveChanges();
            return(paymentsArray);
        }
        public IActionResult RegistrationSave(User user)
        {
            System.Console.WriteLine("--------------------------RegistrationSave(1)--------------------------");
            if (ModelState.IsValid)
            {
                // Verify email address is not already registered in users
                var userInDb = dbContext.User.FirstOrDefault(u => u.Email == user.Email);
                if (userInDb != null)
                {
                    ModelState.AddModelError("Email", "This Email Address is already registered.");
                    setLayoutViewBag();
                    return(View("Registration"));
                }

                // Verify password and confirm password match
                if (user.Password != user.ConfirmPassword)
                {
                    ModelState.AddModelError("Password", "Password does not match Confirm Password.");
                    setLayoutViewBag();
                    return(View("Registration"));
                }


                // Initialize PasswordHasher so we can saved the user's password as a hashed string
                PasswordHasher <User> hasher = new PasswordHasher <User>();
                user.Password = hasher.HashPassword(user, user.Password);

                int      userCount = dbContext.User.ToList().Count;
                DateTime now       = DateTime.Now;
                user.CreatedAt = now;
                user.UpdatedAt = now;
                user.UserLevel = (userCount == 0 ? 1 : 2);  // First logged in user is assigned Admin (1) UserLevel; otherwise Normal (2)
                dbContext.Add(user);
                dbContext.SaveChanges();

                // Log user in
                logUserIn(user);

                System.Console.WriteLine("--------------------------RegistrationSave(2)--------------------------");
                System.Console.WriteLine($"LoggedIn.............: {HttpContext.Session.GetInt32("LoggedIn")}");
                System.Console.WriteLine($"LoggedInUserLevel....: {HttpContext.Session.GetInt32("LoggedInUserLevel")}");
                System.Console.WriteLine($"LoggedInUserSk.......: {HttpContext.Session.GetInt32("LoggedInUserSk")}");
                System.Console.WriteLine($"LoggedInUserEmail....: {HttpContext.Session.GetString("LoggedInUserEmail")}");
                System.Console.WriteLine($"LoggedInUserFirstName: {HttpContext.Session.GetString("LoggedInUserFirstName")}");
                System.Console.WriteLine($"LoggedInUserLastName.: {HttpContext.Session.GetString("LoggedInUserLastName")}");

                System.Console.WriteLine("-----------------------------RegistrationSave(3)------------------------------");
                System.Console.WriteLine($"Action: {this.SuccessAction}, Controller: {this.SuccessController}, UserSk: {user.UserSk}");
                return(RedirectToAction(this.SuccessAction, this.SuccessController, new { userSk = user.UserSk }));
                // return View("Success");
            }
            else
            {
                System.Console.WriteLine("--------------------------RegistrationSave(4)--------------------------");
                setLayoutViewBag();
                return(View("Registration"));
            }
        }
示例#11
0
 public int AddChampion(ChampionsOwned champ)
 {
     _context.Add(champ);
     _context.SaveChanges();
     champ.ChampionOwnedStats = CreateChampionOwnedStats(champ.Id);
     _context.Update(champ);
     _context.SaveChanges();
     return(champ.Id);
 }
 public IActionResult Create([FromBody] User item)
 {
     if (!db.Users.Any(u => u.Email == item.Email))
     {
         db.Add(item);
         db.SaveChanges();
         return(Ok(item));
     }
     return(BadRequest(new Status(400, "No se puede agregar porque el email existe.")));
 }
示例#13
0
        public async Task <IActionResult> Create([Bind("Id,Name,Address,Age,Dob,Phone")] UserProfile userProfile)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userProfile);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userProfile));
        }
        public async Task <IActionResult> Create([Bind("BpdbDivisionId,BpdbDivisionName")] LookUpUserBpdbDivision lookUpUserBpdbDivision)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lookUpUserBpdbDivision);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lookUpUserBpdbDivision));
        }
示例#15
0
 public IActionResult Register([FromBody] User user)
 {
     if (!db.Users.Any(u => u.Email == user.Email))
     {
         user.Password = new PasswordHasher().Hash(user.Password);
         db.Add(user);
         db.SaveChanges();
         return(Ok());
     }
     return(BadRequest(new Status(400, "No se puede agregar porque el email existe.")));
 }
示例#16
0
        public async Task <IActionResult> Create([Bind("UserActivationStatusId,UserActivationStatus")] LookUpUserActivationStatus lookUpUserActivationStatus)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lookUpUserActivationStatus);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lookUpUserActivationStatus));
        }
示例#17
0
        public async Task <IActionResult> Create([Bind("GroupId,Name")] Group @group)
        {
            if (ModelState.IsValid)
            {
                _context.Add(@group);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(@group));
        }
示例#18
0
        public async Task <IActionResult> Create([Bind("ID,FirstName,LastName,PhoneNumber,Address,Email,BirthDate")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
        public async Task <IActionResult> Create([Bind("ContentTypeId,ContentTypeName")] LookUpUserContentType lookUpUserContentType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lookUpUserContentType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(lookUpUserContentType));
        }
示例#20
0
        public async Task <IActionResult> Create([Bind("ID,DogName,Age,Breed,Illness,EnteredShelter")] Dogs dogs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dogs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dogs));
        }
示例#21
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Role role)
        {
            if (ModelState.IsValid)
            {
                _context.Add(role);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(role));
        }
示例#22
0
        public async Task <IActionResult> Create([Bind("id")] User user)
        {
            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(user));
        }
示例#23
0
        public async Task <ActionResult <User> > Create([FromBody] User user)
        {
            if (user == null)
            {
                return(BadRequest());
            }

            _context.Add(user);

            return(await CreateOrUpdateAsync(() =>
                                             CreatedAtAction(nameof(Get), new { id = user.Id }, user) as ActionResult));
        }
        public async Task <IActionResult> Create([Bind("UsersPermittedContentId,ContentTypeId,ContentName,ContentTitle,ContentDescription,ModelName,ControllerName,ActionName")] LookUpUsersPermittedContent lookUpUsersPermittedContent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lookUpUsersPermittedContent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ContentTypeId"] = new SelectList(_context.UserContentType, "ContentTypeId", "ContentTypeName", lookUpUsersPermittedContent.ContentTypeId);
            return(View(lookUpUsersPermittedContent));
        }
        public async Task <IActionResult> Create([Bind("PermissionTypeId,UsersPermittedContentId,Id")] TblUserGrpWisePermissionDetail tblUserGrpWisePermissionDetail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tblUserGrpWisePermissionDetail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["Id"] = new SelectList(_context.Roles, "Id", "Name", tblUserGrpWisePermissionDetail.Id);
            ViewData["UsersPermittedContentId"] = new SelectList(_context.UsersPermittedContent, "UsersPermittedContentId", "UsersPermittedContentId", tblUserGrpWisePermissionDetail.UsersPermittedContentId);
            return(View(tblUserGrpWisePermissionDetail));
        }
        public async Task <IActionResult> Create([Bind("BpdbEmployeeId,BpdbEmployeeLevel,BpdbDivisionId,BpdbEmpDesignation,ZoneCode,CircleCode,SnDCode,SubstationId")] LookUpUserBpdbEmployee lookUpUserBpdbEmployee)
        {
            if (ModelState.IsValid)
            {
                _context.Add(lookUpUserBpdbEmployee);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["BpdbDivisionId"] = new SelectList(_context.UserBpdbDivision, "BpdbDivisionId", "BpdbDivisionName", lookUpUserBpdbEmployee.BpdbDivisionId);
            ViewData["ZoneCode"]       = new SelectList(_contextPDB.LookUpZoneInfo.OrderBy(d => d.ZoneCode), "ZoneCode", "ZoneName");
            return(View(lookUpUserBpdbEmployee));
        }
示例#27
0
 public IActionResult UserRegistration(CodeFirst.Models.UserRegistration userRegistration)
 {
     if (userRegistration != null)
     {
         _userDbContext.Add(userRegistration);
         _userDbContext.SaveChanges();
         return(RedirectToAction("UserLogin", "UserLogin"));
     }
     else
     {
         return(View());
     }
 }
示例#28
0
 public IActionResult UserProfile(CodeFirst.Models.UserProfile userProfile)
 {
     if (userProfile != null)
     {
         _userDbContext.Add(userProfile);
         _userDbContext.SaveChanges();
         return(RedirectToAction("Index", "UserSummary"));
     }
     else
     {
         return(View());
     }
 }
示例#29
0
        public async Task <IActionResult> Create([Bind("LinkId,UserId,Title,LinkAddress,AddingData")] Link link)
        {
            var user = HttpContext.Session.GetString("UserID");

            link.AddingData = DateTime.Today;
            link.UserId     = Convert.ToInt16(user);

            if (!Uri.IsWellFormedUriString(link.LinkAddress, UriKind.Absolute))
            {
                ModelState.AddModelError("", "Nieprawidłowy adres wpisanego linku.");
                return(View());
            }

            if (ModelState.IsValid)
            {
                _context.Add(link);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(RedirectToAction("Profile", "Link", new { area = "" }));
            //return View(link);
        }
        public IActionResult UserLogin(CodeFirst.Models.UserLogin l)
        {
            if (l != null)
            {
                _userDbContext.Add(l);
                _userDbContext.SaveChanges();
                return(RedirectToAction("UserProfile", "UserProfile"));
            }

            else
            {
                return(View());
            }
        }