Example #1
0
        public async Task <bool> AddUserAsync(User user)
        {
            user.UserId = Guid.NewGuid().ToString(); // Id is of type string but is generated by a GUID
            await Users.AddAsync(user);

            await SaveChangesAsync();

            return(true);
        }
Example #2
0
        public async Task AddUser(User user)
        {
            if (Users.Find(user.Email) != null)
            {
                throw new AuthenticationFailedException("The user already exists");
            }
            await Users.AddAsync(user);

            await SaveChangesAsync();
        }
Example #3
0
        public async Task <IActionResult> SignUp(string username, string password, DateTime dob, string name)
        {
            await _bllUsers.AddAsync(new BO.Users()
            {
                Username = username,
                Password = password,
                Dob      = dob,
                Name     = name,
                RoleId   = 2
            });

            return(RedirectToAction("Index"));
        }
Example #4
0
        public async Task <OperationResult <string> > AddAsync(User role, CancellationToken cancellation)
        {
            try
            {
                await Users.AddAsync(role, cancellation);

                return(OperationResult <string> .BuildSuccessResult("Success Add"));
            }
            catch (Exception ex)
            {
                return(OperationResult <string> .BuildFailure(ex.Message));
            }
        }
Example #5
0
        public async Task <bool> TryToAddUserAsync(User user)
        {
            if (Users.FirstOrDefault(u => u.Email == user.Email) != null)
            {
                return(false);
            }

            await Users.AddAsync(user);

            await SaveChangesAsync();

            return(true);
        }
Example #6
0
        public async Task AddUserAsync(string email, string accountName, string password)
        {
            var user = new User
            {
                Email            = email,
                Role             = Role.User,
                RegistrationDate = DateTime.Now,
                Id = Guid.NewGuid()
            };

            await Users.AddAsync(user);

            await AddAccountAsync(user, accountName, password);

            await SaveChangesAsync();
        }
Example #7
0
        public async Task <SecretSantaUser> CreateOrUpdateUser(Message message)
        {
            var secretSantaUser = Users.SingleOrDefault(u => u.Id == message.From.Id);

            if (secretSantaUser is not null)
            {
                secretSantaUser.ChartId      = message.Chat.Id;
                secretSantaUser.FirstName    = message.From.FirstName;
                secretSantaUser.LastName     = message.From.LastName;
                secretSantaUser.Username     = message.From.Username;
                secretSantaUser.ModifiedDate = DateTime.Now;
            }
            else
            {
                secretSantaUser = new SecretSantaUser
                {
                    Id           = message.From.Id,
                    ChartId      = message.Chat.Id,
                    FirstName    = message.From.FirstName,
                    LastName     = message.From.LastName,
                    Username     = message.From.Username,
                    CreatedDate  = DateTime.Now,
                    ModifiedDate = DateTime.Now
                };

                await Users.AddAsync(secretSantaUser);
            }

            await Database.OpenConnectionAsync();

            try
            {
                await Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.Users ON");
                await SaveChangesAsync();

                await Database.ExecuteSqlRawAsync("SET IDENTITY_INSERT dbo.Users OFF");
            }
            finally
            {
                await Database.CloseConnectionAsync();
            }

            return(secretSantaUser);
        }
Example #8
0
        public async Task <object[]> AddUserAsync(User user)
        {
            var userObj = new object[2];

            Debug.WriteLine("Adding new user...");
            try
            {
                await Users.AddAsync(user).ConfigureAwait(false);
                await SaveChangesAsync().ConfigureAwait(false);

                userObj[0] = user;
                userObj[1] = true;
                return(userObj);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Exception occured while trying to add user {e.Message}");
                userObj[0] = e.Message;
                userObj[1] = false;
                return(userObj);
            }
        }
Example #9
0
        /// <summary>
        /// Creates new chat user and throws an exception if there is any user using the given accountId
        /// </summary>
        /// <param name="user">The user to create </param>
        /// <param name="accoutId"></param>
        /// <exception cref="ArgumentException">Throws when the accountId is already has chat user registered </exception>
        public async Task <User> CreateUserAsync(User user, string accoutId)
        {
            NotNull(user, nameof(user));
            accoutId = accoutId ?? user.AccountId;
            NotNull(accoutId, nameof(accoutId));

            var existUser = await Users.SingleOrDefaultAsync(u => u.AccountId == accoutId);

            if (existUser != null)
            {
                throw new ArgumentException($"Error Occurred while creating new Chat User {Environment.NewLine}" +
                                            $"there are exist user using the given AccountId !");
            }
            user.AccountId = accoutId;
            user.Id        = Guid.NewGuid().ToString();
            var entry = await Users.AddAsync(user);

            entry.State = EntityState.Added;
            await Db.SaveChangesAsync();

            return(user);
        }
Example #10
0
        private async Task FillWithTestData()
        {
            // создаем объекты
            var user = new User
            {
                Login    = MoqDataGenerator.GetRandomString(10),
                Password = MoqDataGenerator.GetRandomString(10),
                Nickname = MoqDataGenerator.GetRandomString(10),
                UserID   = MoqDataGenerator.GetRandomNumber(1, 100)
            };

            var account = new Account
            {
                AccountID   = MoqDataGenerator.GetRandomNumber(1, 100),
                Name        = MoqDataGenerator.GetRandomString(10),
                Description = MoqDataGenerator.GetRandomString(100)
            };

            var payment = new Payment
            {
                Date      = DateTime.Now,
                PaymentID = MoqDataGenerator.GetRandomNumber(1, 100),
                Value     = MoqDataGenerator.GetRandomNumber(1, 1000),
                Text      = MoqDataGenerator.GetRandomString(1000)
            };

            var userAccount = new UserAccount
            {
                UserAccountID = MoqDataGenerator.GetRandomNumber(1, 100)
            };

            var token = new Token
            {
                Value = MoqDataGenerator.GetRandomString(10)
            };


            // устанавливаем связи
            account.UserAccounts = new List <UserAccount> {
                userAccount
            };
            account.Payments = new List <Payment> {
                payment
            };
            payment.User      = user;
            payment.UserID    = user.UserID;
            payment.Account   = account;
            user.UserAccounts = new List <UserAccount> {
                userAccount
            };
            user.Payments = new List <Payment> {
                payment
            };
            userAccount.User      = user;
            userAccount.Account   = account;
            userAccount.UserID    = user.UserID;
            userAccount.AccountID = account.AccountID;
            token.User            = user;
            token.UserID          = user.UserID;

            await Accounts.AddAsync(account);

            await Payments.AddAsync(payment);

            await Users.AddAsync(user);

            await UserAccounts.AddAsync(userAccount);

            await Tokens.AddAsync(token);
        }
Example #11
0
        public async Task InsertUserAsync(User user)
        {
            await Users.AddAsync(user);

            await SaveChangesAsync();
        }