コード例 #1
0
ファイル: MasterDataProvider.cs プロジェクト: ssssossss/sai
        protected virtual VM_UserDetails GetContactPersonIFNFromReader(IDataReader reader)
        {
            EntityConverter <VM_UserDetails> userDetailEntity = new EntityConverter <VM_UserDetails>();
            VM_UserDetails userDetail = userDetailEntity.Convert(reader);

            return(userDetail);
        }
コード例 #2
0
        protected virtual VM_UserDetails GetIfnUserFromReader(IDataReader iDataReader)
        {
            EntityConverter <VM_UserDetails> userDetailEntity = new EntityConverter <VM_UserDetails>();
            VM_UserDetails userDetailVM = userDetailEntity.Convert(iDataReader);

            return(userDetailVM);
        }
コード例 #3
0
        protected virtual VM_UserDetails GetUserDetailsByUserIdFromReader(IDataReader reader)
        {
            EntityConverter <VM_UserDetails> usr             = new EntityConverter <VM_UserDetails>();
            EntityConverter <UserRole>       userRolesEntity = new EntityConverter <UserRole>();
            VM_UserDetails user      = new VM_UserDetails();
            UserRole       userRoles = new UserRole();

            if (reader.Read())
            {
                user = usr.Convert(reader);
            }

            if (reader.NextResult())
            {
                while (reader.Read())
                {
                    userRoles = userRolesEntity.Convert(reader);
                    user.Roles.Add(userRoles);
                }
            }
            return(user);
        }
コード例 #4
0
        public int InsertUpdateUserDetails(VM_UserDetails userDetails)
        {
            using (SqlConnection cn = new SqlConnection(this.ConnectionString))
            {
                SqlTransaction sqlTrans;
                cn.Open();
                sqlTrans = cn.BeginTransaction();
                int UserId = 0;
                try
                {
                    SqlCommand cmd = new SqlCommand();
                    if (userDetails.UserID == 0)
                    {
                        cmd             = new SqlCommand("[Admin_InsertUsersTable]", cn);
                        cmd.Transaction = sqlTrans;
                        cmd.Parameters.AddWithValue("@Username", userDetails.Username);
                        cmd.Parameters.AddWithValue("@FirstName", userDetails.FirstName);
                        cmd.Parameters.AddWithValue("@LastName", userDetails.LastName);
                        cmd.Parameters.AddWithValue("@Location", userDetails.Location);
                        cmd.Parameters.AddWithValue("@CreatedBy", userDetails.CreatedBy);
                        cmd.CommandType = CommandType.StoredProcedure;
                        SqlParameter sqlparam = new SqlParameter();
                        sqlparam.ParameterName = "@UserId";
                        sqlparam.DbType        = DbType.Int32;
                        sqlparam.Direction     = ParameterDirection.Output;
                        cmd.Parameters.Add(sqlparam);
                        cmd.ExecuteNonQuery();
                        UserId = Convert.ToInt32(cmd.Parameters["@UserId"].Value);
                    }
                    else
                    {
                        cmd             = new SqlCommand("[Admin_UpdateUsersTable]", cn);
                        cmd.Transaction = sqlTrans;
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@UserId", userDetails.UserID);
                        cmd.Parameters.AddWithValue("@IsActive", userDetails.IsActive);
                        cmd.Parameters.AddWithValue("@ModifiedBy", userDetails.ModifiedBy);
                        cmd.Parameters.AddWithValue("@ModifiedByIP", userDetails.ModifiedByIP);
                        if (ExecuteNonQuery(cmd) != 0)
                        {
                            UserId = userDetails.UserID;
                        }
                    }


                    cmd             = new SqlCommand("[Admin_InsertUpdateUserRoles]", cn);
                    cmd.Transaction = sqlTrans;
                    cmd.Parameters.AddWithValue("@UserId", UserId);
                    cmd.CommandType = CommandType.StoredProcedure;
                    foreach (var item in userDetails.Roles)
                    {
                        item.UserId = UserId;
                    }
                    SqlParameter userRoles = cmd.Parameters.AddWithValue("@UserRoles", ConvertToDataTable <UserRole>(userDetails.Roles));
                    userRoles.TypeName  = "dbo.tvp_AdminUserRoles";
                    userRoles.SqlDbType = SqlDbType.Structured;

                    cmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    try
                    {
                        sqlTrans.Rollback();
                        cn.Close();
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                    throw;
                }
                sqlTrans.Commit();
                cn.Close();
                return(UserId);
            }
        }