Beispiel #1
0
        private async Task <bool> saveStudent(Interfaces.IConnectionUtility connection, ViewModels.StudentVM student)
        {
            student.Id = Guid.NewGuid().ToString();

            using (var conn = connection.GetConnection())
            {
                conn.Open();
                var tran = conn.BeginTransaction();
                try
                {
                    await DB.DBUtility.Insert <DBModels.StudentEntity>(tran.Connection,
                                                                       new DBModels.StudentEntity[] { Mappers.ObjectMapper.Instance.Mapper.Map <DBModels.StudentEntity>(student) });

                    var userEntity = new DBModels.UserEntity();
                    userEntity.id            = student.Id;
                    userEntity.user_email    = student.StudentEmail;
                    userEntity.is_confirmed  = true;
                    userEntity.is_locked_out = false;
                    userEntity.num_of_failed_password_attempt = 0;

                    var createUserResult = await CreateUser(tran.Connection, userEntity, student.Password);

                    tran.Commit();

                    return(createUserResult.Success);
                }
                catch
                {
                    tran.Rollback();
                }
                finally
                {
                    tran.Dispose();
                }
            }

            return(false);
        }
Beispiel #2
0
        public async Task <Logic.Models.CreateUserResult> CreateUser(System.Data.IDbConnection conn, DBModels.UserEntity userEntity, string password)
        {
            var result = new Logic.Models.CreateUserResult();

            try
            {
                result.Success = true;

                var entity = await getUser(conn, userEntity.user_email);

                if (entity != null)
                {
                    result.Success = false;
                    result.Reason  = Enums.CreateUserReason.UserAlreadyExist;
                    return(result);
                }

                var parameters = new System.Collections.Generic.Dictionary <string, object>();
                parameters.Add("user_email", userEntity.user_email);
                parameters.Add("id", userEntity.id);
                parameters.Add("login_password", password);
                parameters.Add("token", Constants.Constants.TOKEN_TEXT);

                string createdUserId = await DB.DBUtility.GetScalar <string>(conn, @"
                    INSERT INTO USERS(id, user_email, login_password, last_login_on, last_log_out, is_locked_out, is_confirmed, 
                    num_of_failed_password_attempt, is_deleted, modified_on)
                    VALUES(@id, @user_email, AES_ENCRYPT(@login_password, @token), NULL, NULL, FALSE, TRUE, 0, FALSE, UTC_TIMESTAMP());

                    SELECT @id;
                    ", parameters);

                Guid uuid;
                if (createdUserId != null && Guid.TryParse(createdUserId, out uuid))
                {
                    result.UserId  = createdUserId.ToString();
                    result.Success = true;
                }
            }
            finally
            {
            }

            return(result);
        }
Beispiel #3
0
 public async Task <Logic.Models.CreateUserResult> CreateUser(Interfaces.IConnectionUtility connectionUtility, DBModels.UserEntity userEntity, string password)
 {
     using (var conn = connectionUtility.GetConnection())
     {
         return(await CreateUser(conn, userEntity, password));
     }
 }